fimo 0.6.0 → 0.7.0-experimental.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/content-templates/hooks-template.eta +73 -27
- package/assets/content-templates/types-template.eta +4 -1
- package/assets/skills/fimo/references/content.md +46 -42
- package/assets/skills/fimo-cli/references/content.md +14 -14
- package/dist/cli/bundle.json +1 -1
- package/dist/cli/index.js +250 -29
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts +1 -0
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts.map +1 -1
- package/dist/runtime/content/utils/retrieve-data-sources.js +27 -4
- package/dist/runtime/primitives/lib/primitives.d.ts +2 -2
- package/dist/runtime/primitives/lib/primitives.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/query.d.ts +5 -3
- package/dist/runtime/primitives/lib/query.d.ts.map +1 -1
- package/dist/runtime/primitives/public-surface.test.js +9 -5
- package/dist/scripts/generated-types.test.js +1 -1
- package/dist/scripts/sync-schemas.test.js +24 -4
- package/dist/scripts/validate-schemas.test.js +2 -2
- package/package.json +1 -1
- package/release.json +2 -2
- package/templates/react-router/package.json +1 -1
|
@@ -37,6 +37,8 @@ describe('syncSchemas', () => {
|
|
|
37
37
|
const post = readFileSync(join(scratch, 'src/schemas/Post.ts'), 'utf-8');
|
|
38
38
|
const postTypes = readFileSync(join(scratch, 'src/schemas/Post.types.ts'), 'utf-8');
|
|
39
39
|
expect(post).toContain('import { wrapWithSource as wrapAuthorWithSource } from "./Author";');
|
|
40
|
+
expect(post).toContain('isPopulatedEntry(value) ? wrapAuthorWithSource(value) : value');
|
|
41
|
+
expect(post).toContain('function isPopulatedEntry(value: unknown): value is PopulatedEntryRecord');
|
|
40
42
|
expect(post).toContain('import type { Post, PostInput, PostPopulate, PostResult, PostFields, PostQuery } from "./Post.types";');
|
|
41
43
|
expect(post).toContain('from "./Post.types";');
|
|
42
44
|
expect(post).not.toContain('import type { Author } from "./Author";');
|
|
@@ -47,9 +49,22 @@ describe('syncSchemas', () => {
|
|
|
47
49
|
expect(post).toContain('wrapAuthorWithSource(value)');
|
|
48
50
|
expect(post).toContain('wrapWithSource(value)');
|
|
49
51
|
expect(post).toContain('export async function create(payload: PostInput): Promise<Post>');
|
|
52
|
+
expect(post).toContain('export async function getById');
|
|
53
|
+
expect(post).toContain('string | { id: string; locale?: string }');
|
|
54
|
+
expect(post).toContain('typeof value === "string"');
|
|
55
|
+
expect(post).toContain('/entries/Post/');
|
|
56
|
+
expect(post).not.toContain('/v2/entries');
|
|
50
57
|
expect(post).toContain('return wrapWithSource(data.data);');
|
|
58
|
+
expect(post).toContain('mutationFn : (payload) => create(withMutationLocale(payload, activeLocale))');
|
|
59
|
+
expect(post).toContain('mutationFn : ({ id, ...patch }) => update(id, withMutationLocale(patch, activeLocale))');
|
|
60
|
+
expect(post).toContain('qk.byId(vars.id, { locale: vars.locale ?? activeLocale })');
|
|
61
|
+
expect(post).toContain('{ ...value, locale: value.locale ?? activeLocale }');
|
|
51
62
|
expect(postTypes).toContain('import type { Author } from "./Author.types";');
|
|
52
63
|
expect(postTypes).toContain('export interface Post extends WithReferences<PostReferences>');
|
|
64
|
+
expect(postTypes).toContain(' id: string;');
|
|
65
|
+
expect(postTypes).toContain(' entryId: string;');
|
|
66
|
+
expect(postTypes).toContain(' documentId: string;');
|
|
67
|
+
expect(postTypes).toContain(' locale: string;');
|
|
53
68
|
expect(postTypes).toContain('type FimoReference');
|
|
54
69
|
expect(postTypes).toContain('author: FimoReference | null;');
|
|
55
70
|
expect(postTypes).toContain('contributors: FimoReference[];');
|
|
@@ -63,7 +78,7 @@ describe('syncSchemas', () => {
|
|
|
63
78
|
expect(postTypes).toContain('export type PostResult<');
|
|
64
79
|
expect(postTypes).not.toContain('PostPopulated');
|
|
65
80
|
});
|
|
66
|
-
it('generates locale
|
|
81
|
+
it('generates effective-locale shared types and locale-sensitive populated target keys', () => {
|
|
67
82
|
writeSchema('Homepage', {
|
|
68
83
|
uid: 'Homepage',
|
|
69
84
|
name: 'Homepages',
|
|
@@ -88,15 +103,15 @@ describe('syncSchemas', () => {
|
|
|
88
103
|
const settings = readFileSync(join(scratch, 'src/schemas/Settings.ts'), 'utf-8');
|
|
89
104
|
const settingsTypes = readFileSync(join(scratch, 'src/schemas/Settings.types.ts'), 'utf-8');
|
|
90
105
|
const homepageTypes = readFileSync(join(scratch, 'src/schemas/Homepage.types.ts'), 'utf-8');
|
|
91
|
-
expect(settingsTypes).
|
|
106
|
+
expect(settingsTypes).toContain('locale: string;');
|
|
92
107
|
expect(settingsTypes).not.toContain('locale?: string;');
|
|
93
108
|
expect(homepageTypes).toContain('locale: string;');
|
|
94
109
|
expect(settings).toContain('const LOCALIZED_CONTENT = false;');
|
|
95
110
|
expect(settings).toContain('const LOCALIZED_REFERENCE_FIELDS = new Set<string>(["homepage"]);');
|
|
96
|
-
expect(settings).
|
|
111
|
+
expect(settings).toContain(' locale,');
|
|
97
112
|
expect(settings).toContain('readLocale(params, LOCALIZED_CONTENT, useQueryLocale(params.locale))');
|
|
98
113
|
expect(settings.match(/readLocale\(params, LOCALIZED_CONTENT, useQueryLocale\(params\.locale\)\)/g)?.length).toBe(4);
|
|
99
|
-
expect(settings.match(/
|
|
114
|
+
expect(settings.match(/const locale = useQueryLocale\(options\.locale\);/g)?.length).toBe(2);
|
|
100
115
|
});
|
|
101
116
|
it('generates singleton document APIs without collection mutations', () => {
|
|
102
117
|
writeSchema('Settings', {
|
|
@@ -110,7 +125,12 @@ describe('syncSchemas', () => {
|
|
|
110
125
|
const settings = readFileSync(join(scratch, 'src/schemas/Settings.ts'), 'utf-8');
|
|
111
126
|
const settingsTypes = readFileSync(join(scratch, 'src/schemas/Settings.types.ts'), 'utf-8');
|
|
112
127
|
expect(settings).toContain('fetch(`${base}${withReadOptions(`/documents/Settings`, options)}`');
|
|
128
|
+
expect(settings).toContain('`Settings.id:${id}:${encodeURIComponent(locale)}`');
|
|
129
|
+
expect(settingsTypes).toContain('id: string;');
|
|
130
|
+
expect(settingsTypes).toContain('entryId: string;');
|
|
131
|
+
expect(settingsTypes).toContain('locale?: string;');
|
|
113
132
|
expect(settings).toContain('export async function update(payload: Partial<SettingsInput>)');
|
|
133
|
+
expect(settings).toContain('mutationFn: (payload) => update(withMutationLocale(payload, activeLocale))');
|
|
114
134
|
expect(settings).toContain('export function useSuspenseGet');
|
|
115
135
|
expect(settings).not.toContain('export async function create(');
|
|
116
136
|
expect(settings).not.toContain('export async function remove(');
|
|
@@ -117,14 +117,14 @@ describe('validateSchemas', () => {
|
|
|
117
117
|
'Bad.json': {
|
|
118
118
|
uid: 'Bad',
|
|
119
119
|
name: 'Bad',
|
|
120
|
-
fields: Object.fromEntries(['id', 'documentId', 'slug', 'locale', 'createdAt', 'updatedAt', '__fimo'].map((name) => [
|
|
120
|
+
fields: Object.fromEntries(['id', 'entryId', 'documentId', 'slug', 'locale', 'createdAt', 'updatedAt', '__fimo'].map((name) => [
|
|
121
121
|
name,
|
|
122
122
|
{ type: 'string' },
|
|
123
123
|
])),
|
|
124
124
|
},
|
|
125
125
|
});
|
|
126
126
|
const { errors } = validateSchemas({ cwd });
|
|
127
|
-
expect(errors).toHaveLength(
|
|
127
|
+
expect(errors).toHaveLength(8);
|
|
128
128
|
expect(errors.every((err) => err.rule === 'schemas/reserved-field')).toBe(true);
|
|
129
129
|
});
|
|
130
130
|
it('rejects unsupported field types', () => {
|
package/package.json
CHANGED
package/release.json
CHANGED