Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: directus 11.3.3 compatibility #128

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Directus Sync

![Directus 11.3.2](https://img.shields.io/badge/Directus-11.3.2-64f?style=for-the-badge&logo=directus)
![Directus 11.3.3](https://img.shields.io/badge/Directus-11.3.3-64f?style=for-the-badge&logo=directus)

> [!IMPORTANT]
> Latest version of `directus-sync` introduces breaking changes and is not compatible with Directus 10.x.x.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Directus Sync

![Directus 11.3.2](https://img.shields.io/badge/Directus-11.3.2-64f?style=for-the-badge&logo=directus)
![Directus 11.3.3](https://img.shields.io/badge/Directus-11.3.3-64f?style=for-the-badge&logo=directus)
[![Donate](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/Directus-Sync/donate)
[![Discord](https://img.shields.io/badge/Discord-Join-5865F2?style=for-the-badge&logo=discord)](https://discord.gg/4vGzHPQmud)

Expand Down
2 changes: 1 addition & 1 deletion docker/build-and-push.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zx

const latestDirectusVersion = '11.3.2';
const latestDirectusVersion = '11.3.3';
const [major, minor, patch] = latestDirectusVersion.split('.');
const directusVersions = [
'latest',
Expand Down
119 changes: 32 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@directus/sdk": "^17.0.1",
"case": "^1.6.3",
"commander": "^12.1.0",
"compare-versions": "^6.1.1",
"deep-object-diff": "^1.1.9",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/lib/commands/seed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './push';
26 changes: 26 additions & 0 deletions packages/cli/src/lib/commands/seed/push.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Container } from 'typedi';
import pino from 'pino';
import { MigrationClient, SeedClient } from '../../services';
import { LOGGER } from '../../constants';

export async function runSeedPush() {
const logger: pino.Logger = Container.get(LOGGER);
const seedClient = Container.get(SeedClient);

// Check and prepare instance
const migrationClient = Container.get(MigrationClient);
await migrationClient.validateDirectusVersion();
await migrationClient.clearCache();

// Clean up the seed (dangling id maps, etc.)
logger.info(`---- Clean up seeds ----`);
await seedClient.cleanUp();

let stop = false;
let index = 1;
while (!stop) {
logger.info(`---- Push: iteration ${index} ----`);
stop = !(await seedClient.push()); // Return true when should retry
index++;
}
}
18 changes: 18 additions & 0 deletions packages/cli/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ export function loadJsonFilesRecursively<T>(dirPath: string): T[] {
return files;
}

/**
* Recursively load json files from a directory and validate them against a zod schema
* The root path could be a folder or a JSON file
*/
export function loadJsonFilesRecursivelyWithSchema<T extends ZodSchema>(
rootPath: string,
schema: T,
errorContext?: string,
): z.infer<T>[] {
if (rootPath.endsWith('.json')) {
const file = readJsonSync(rootPath, 'utf-8');
return [zodParse(file, schema, errorContext)];
}
return loadJsonFilesRecursively(rootPath).map((file) =>
zodParse(file, schema, errorContext),
);
}

/**
* Validate an object against a zod schema and format the error if it fails
*/
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/lib/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
runRemovePermissionDuplicates,
runUntrack,
} from './index';
import { runSeedPush } from './commands/seed';

/**
* Remove some default values from the program options that overrides the config file
Expand Down Expand Up @@ -209,6 +210,25 @@
.addOption(forceOption)
.action(wrapAction(program, runPush));

// ---------------------------------------------------------------------------------
// Seed
const seedPathOption = new Option(
'--seed-path <seedPath...>',
`the base path(s) for the seed (default "${DefaultConfig.seedPath}")`,

Check failure on line 217 in packages/cli/src/lib/program.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Invalid type "string | string[]" of template literal expression
);

const seed = program
.command('seed')
.description('seed the custom collections with data');

seed
.command('push')
.description('push the seed data')
.addOption(seedPathOption)
.action(wrapAction(program, runSeedPush));

// ---------------------------------------------------------------------------------
// Helpers
const helpers = program
.command('helpers')
.description('a set of helper utilities');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export abstract class IdMapperClient extends ExtensionClient {
`/table/${this.table}`,
'POST',
{
table: this.table,
table: this.table, // TODO: Could remove this (to be tested)
local_id: localId,
sync_id: syncId,
},
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/lib/services/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ export class ConfigService {
};
}

@Cacheable()
getSeedConfig() {
const paths = this.requireOptions('seedPath');
const seedPaths = Array.isArray(paths) ? paths : [paths];
const seedFullPaths = seedPaths.map((p) => Path.resolve(p));
return {
paths: seedFullPaths,
};
}

/**
* Returns the Directus config, either with a token or with an email/password
*/
Expand Down
Loading
Loading