@nuasite/cms-core 0.64.3 → 0.65.0
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/dist/asset-paths.d.ts.map +1 -0
- package/dist/asset-paths.js +55 -0
- package/dist/astro-source-analysis.d.ts.map +1 -0
- package/dist/astro-source-analysis.js +503 -0
- package/dist/byte-range.d.ts.map +1 -0
- package/dist/byte-range.js +31 -0
- package/dist/{types/check-entries.d.ts → check-entries.d.ts} +3 -3
- package/dist/check-entries.d.ts.map +1 -0
- package/dist/check-entries.js +98 -0
- package/dist/{types/check-live.d.ts → check-live.d.ts} +4 -4
- package/dist/check-live.d.ts.map +1 -0
- package/dist/check-live.js +49 -0
- package/dist/{types/check-shape.d.ts → check-shape.d.ts} +4 -4
- package/dist/check-shape.d.ts.map +1 -0
- package/dist/check-shape.js +119 -0
- package/dist/{types/check-write.d.ts → check-write.d.ts} +4 -4
- package/dist/check-write.d.ts.map +1 -0
- package/dist/check-write.js +273 -0
- package/dist/{types/check.d.ts → check.d.ts} +2 -2
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +366 -0
- package/dist/{types/collection-scanner.d.ts → collection-scanner.d.ts} +2 -2
- package/dist/collection-scanner.d.ts.map +1 -0
- package/dist/collection-scanner.js +1483 -0
- package/dist/{types/component-registry.d.ts → component-registry.d.ts} +1 -1
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +271 -0
- package/dist/{types/content-config-ast.d.ts → content-config-ast.d.ts} +1 -1
- package/dist/content-config-ast.d.ts.map +1 -0
- package/dist/content-config-ast.js +1614 -0
- package/dist/{types/core.d.ts → core.d.ts} +3 -3
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +94 -0
- package/dist/editor-write-model.d.ts.map +1 -0
- package/dist/editor-write-model.js +101 -0
- package/dist/fs/glob.d.ts.map +1 -0
- package/dist/fs/glob.js +79 -0
- package/dist/{types/fs → fs}/node-fs.d.ts +1 -1
- package/dist/fs/node-fs.d.ts.map +1 -0
- package/dist/fs/node-fs.js +199 -0
- package/dist/{types/fs → fs}/staged.d.ts +1 -1
- package/dist/fs/staged.d.ts.map +1 -0
- package/dist/fs/staged.js +203 -0
- package/dist/fs/types.d.ts.map +1 -0
- package/dist/fs/types.js +0 -0
- package/dist/{types/handlers → handlers}/entry-ops.d.ts +2 -2
- package/dist/handlers/entry-ops.d.ts.map +1 -0
- package/dist/handlers/entry-ops.js +846 -0
- package/dist/{types/handlers → handlers}/page-ops.d.ts +1 -1
- package/dist/handlers/page-ops.d.ts.map +1 -0
- package/dist/handlers/page-ops.js +165 -0
- package/dist/{types/handlers → handlers}/redirect-ops.d.ts +1 -1
- package/dist/handlers/redirect-ops.d.ts.map +1 -0
- package/dist/handlers/redirect-ops.js +111 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/media/contember.d.ts.map +1 -0
- package/dist/media/contember.js +79 -0
- package/dist/media/errors.d.ts.map +1 -0
- package/dist/media/errors.js +22 -0
- package/dist/{types/media → media}/file-system.d.ts +1 -1
- package/dist/media/file-system.d.ts.map +1 -0
- package/dist/media/file-system.js +124 -0
- package/dist/{types/media → media}/index.d.ts +8 -8
- package/dist/media/index.d.ts.map +1 -0
- package/dist/media/index.js +8 -0
- package/dist/media/local.d.ts.map +1 -0
- package/dist/media/local.js +209 -0
- package/dist/media/mime.d.ts.map +1 -0
- package/dist/media/mime.js +21 -0
- package/dist/media/names.d.ts.map +1 -0
- package/dist/media/names.js +23 -0
- package/dist/{types/media → media}/project-images.d.ts +1 -1
- package/dist/media/project-images.d.ts.map +1 -0
- package/dist/media/project-images.js +99 -0
- package/dist/media/s3.d.ts.map +1 -0
- package/dist/media/s3.js +160 -0
- package/dist/media/type-filter.d.ts.map +1 -0
- package/dist/media/type-filter.js +164 -0
- package/dist/{types/portable.d.ts → portable.d.ts} +25 -25
- package/dist/portable.d.ts.map +1 -0
- package/dist/portable.js +27 -0
- package/dist/{types/project-config-ast.d.ts → project-config-ast.d.ts} +1 -1
- package/dist/project-config-ast.d.ts.map +1 -0
- package/dist/project-config-ast.js +324 -0
- package/dist/public-static-file.d.ts.map +1 -0
- package/dist/public-static-file.js +40 -0
- package/dist/redirects.d.ts.map +1 -0
- package/dist/redirects.js +185 -0
- package/dist/route-scan.d.ts.map +1 -0
- package/dist/route-scan.js +23 -0
- package/dist/schema-port.d.ts.map +1 -0
- package/dist/schema-port.js +30 -0
- package/dist/{types/schema-probe.d.ts → schema-probe.d.ts} +2 -2
- package/dist/schema-probe.d.ts.map +1 -0
- package/dist/schema-probe.js +119 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +163 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -12
- package/src/check-entries.ts +4 -4
- package/src/check-live.ts +4 -4
- package/src/check-shape.ts +5 -5
- package/src/check-write.ts +6 -6
- package/src/check.ts +15 -9
- package/src/collection-scanner.ts +3 -3
- package/src/component-registry.ts +1 -1
- package/src/content-config-ast.ts +1 -1
- package/src/core.ts +8 -8
- package/src/editor-write-model.ts +1 -1
- package/src/fs/node-fs.ts +2 -2
- package/src/fs/staged.ts +6 -3
- package/src/handlers/entry-ops.ts +7 -7
- package/src/handlers/page-ops.ts +2 -2
- package/src/handlers/redirect-ops.ts +2 -2
- package/src/index.ts +4 -4
- package/src/media/contember.ts +1 -1
- package/src/media/file-system.ts +4 -4
- package/src/media/index.ts +8 -8
- package/src/media/local.ts +3 -3
- package/src/media/project-images.ts +2 -2
- package/src/media/s3.ts +3 -3
- package/src/portable.ts +25 -25
- package/src/project-config-ast.ts +1 -1
- package/src/route-scan.ts +1 -1
- package/src/schema-probe.ts +2 -2
- package/src/tsconfig.json +5 -1
- package/dist/types/asset-paths.d.ts.map +0 -1
- package/dist/types/astro-source-analysis.d.ts.map +0 -1
- package/dist/types/byte-range.d.ts.map +0 -1
- package/dist/types/check-entries.d.ts.map +0 -1
- package/dist/types/check-live.d.ts.map +0 -1
- package/dist/types/check-shape.d.ts.map +0 -1
- package/dist/types/check-write.d.ts.map +0 -1
- package/dist/types/check.d.ts.map +0 -1
- package/dist/types/collection-scanner.d.ts.map +0 -1
- package/dist/types/component-registry.d.ts.map +0 -1
- package/dist/types/content-config-ast.d.ts.map +0 -1
- package/dist/types/core.d.ts.map +0 -1
- package/dist/types/editor-write-model.d.ts.map +0 -1
- package/dist/types/fs/glob.d.ts.map +0 -1
- package/dist/types/fs/node-fs.d.ts.map +0 -1
- package/dist/types/fs/staged.d.ts.map +0 -1
- package/dist/types/fs/types.d.ts.map +0 -1
- package/dist/types/handlers/entry-ops.d.ts.map +0 -1
- package/dist/types/handlers/page-ops.d.ts.map +0 -1
- package/dist/types/handlers/redirect-ops.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/media/contember.d.ts.map +0 -1
- package/dist/types/media/errors.d.ts.map +0 -1
- package/dist/types/media/file-system.d.ts.map +0 -1
- package/dist/types/media/index.d.ts.map +0 -1
- package/dist/types/media/local.d.ts.map +0 -1
- package/dist/types/media/mime.d.ts.map +0 -1
- package/dist/types/media/names.d.ts.map +0 -1
- package/dist/types/media/project-images.d.ts.map +0 -1
- package/dist/types/media/s3.d.ts.map +0 -1
- package/dist/types/media/type-filter.d.ts.map +0 -1
- package/dist/types/portable.d.ts.map +0 -1
- package/dist/types/project-config-ast.d.ts.map +0 -1
- package/dist/types/public-static-file.d.ts.map +0 -1
- package/dist/types/redirects.d.ts.map +0 -1
- package/dist/types/route-scan.d.ts.map +0 -1
- package/dist/types/schema-port.d.ts.map +0 -1
- package/dist/types/schema-probe.d.ts.map +0 -1
- package/dist/types/shared.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- /package/dist/{types/asset-paths.d.ts → asset-paths.d.ts} +0 -0
- /package/dist/{types/astro-source-analysis.d.ts → astro-source-analysis.d.ts} +0 -0
- /package/dist/{types/byte-range.d.ts → byte-range.d.ts} +0 -0
- /package/dist/{types/editor-write-model.d.ts → editor-write-model.d.ts} +0 -0
- /package/dist/{types/fs → fs}/glob.d.ts +0 -0
- /package/dist/{types/fs → fs}/types.d.ts +0 -0
- /package/dist/{types/media → media}/contember.d.ts +0 -0
- /package/dist/{types/media → media}/errors.d.ts +0 -0
- /package/dist/{types/media → media}/local.d.ts +0 -0
- /package/dist/{types/media → media}/mime.d.ts +0 -0
- /package/dist/{types/media → media}/names.d.ts +0 -0
- /package/dist/{types/media → media}/s3.d.ts +0 -0
- /package/dist/{types/media → media}/type-filter.d.ts +0 -0
- /package/dist/{types/public-static-file.d.ts → public-static-file.d.ts} +0 -0
- /package/dist/{types/redirects.d.ts → redirects.d.ts} +0 -0
- /package/dist/{types/route-scan.d.ts → route-scan.d.ts} +0 -0
- /package/dist/{types/schema-port.d.ts → schema-port.d.ts} +0 -0
- /package/dist/{types/shared.d.ts → shared.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AddRedirectRequest, CollectionDefinition, CollectionScanReport, ComponentDefinition, CreatePageRequest, DeletePageRequest, DeleteRedirectRequest, DuplicatePageRequest, GetRedirectsResponse, LayoutInfo, MediaStorageAdapter, MutationResult, PageOperationResponse, RedirectOperationResponse, UpdateRedirectRequest } from '@nuasite/cms-types';
|
|
2
|
-
import { type CmsCommit } from './fs/staged';
|
|
3
|
-
import type { CmsFileSystem } from './fs/types';
|
|
4
|
-
import { type AddArrayItemInput, type CreateEntryInput, type EntryAsset, type GetEntryResult, type RemoveArrayItemInput, type UpdateEntryInput } from './handlers/entry-ops';
|
|
2
|
+
import { type CmsCommit } from './fs/staged.ts';
|
|
3
|
+
import type { CmsFileSystem } from './fs/types.ts';
|
|
4
|
+
import { type AddArrayItemInput, type CreateEntryInput, type EntryAsset, type GetEntryResult, type RemoveArrayItemInput, type UpdateEntryInput } from './handlers/entry-ops.ts';
|
|
5
5
|
export interface CmsCoreOptions {
|
|
6
6
|
/** Content collections directory, relative to the filesystem root. Defaults to `src/content`. */
|
|
7
7
|
contentDir?: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAE,KAAK,SAAS,EAA0B,MAAM,gBAAgB,CAAA;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAEN,KAAK,iBAAiB,EAEtB,KAAK,gBAAgB,EAErB,KAAK,UAAU,EAIf,KAAK,cAAc,EAGnB,KAAK,oBAAoB,EAGzB,KAAK,gBAAgB,EACrB,MAAM,yBAAyB,CAAA;AAchC,MAAM,WAAW,cAAc;IAC9B,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gEAAgE;IAChE,KAAK,CAAC,EAAE,mBAAmB,CAAA;IAC3B,mHAAmH;IACnH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IAEvB;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAA;IAC9F;;;;;OAKG;IACH,oBAAoB,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,GAAG,oBAAoB,G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CAAC,CAAA;IACpE,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IACnC,aAAa,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC9C,WAAW,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAC1E,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAChF,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAGhF,KAAK,CAAC,EAAE,mBAAmB,CAAA;CAC3B;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,GAAE,cAAmB,GAAG,OAAO,CAyFnF"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { collectionScanReport, scanCollections } from "./collection-scanner.js";
|
|
2
|
+
import { scanComponentDefinitions } from "./component-registry.js";
|
|
3
|
+
import {} from "./content-config-ast.js";
|
|
4
|
+
import { createStagedFileSystem } from "./fs/staged.js";
|
|
5
|
+
import { addArrayItem as addArrayItemOp, createEntry as createEntryOp, deleteEntry as deleteEntryOp, getEntry as getEntryOp, getEntryAsset as getEntryAssetOp, getProjectAsset as getProjectAssetOp, removeArrayItem as removeArrayItemOp, renameEntry as renameEntryOp, updateEntry as updateEntryOp, } from "./handlers/entry-ops.js";
|
|
6
|
+
import { createPage as createPageOp, deletePage as deletePageOp, duplicatePage as duplicatePageOp, getLayouts as getLayoutsOp, } from "./handlers/page-ops.js";
|
|
7
|
+
import { addRedirect as addRedirectOp, deleteRedirect as deleteRedirectOp, listRedirects as listRedirectsOp, updateRedirect as updateRedirectOp, } from "./handlers/redirect-ops.js";
|
|
8
|
+
export function createCmsCore(fs, opts = {}) {
|
|
9
|
+
const contentDir = opts.contentDir ?? 'src/content';
|
|
10
|
+
const componentDirs = opts.componentDirs ?? ['src/components'];
|
|
11
|
+
const commit = opts.commit;
|
|
12
|
+
// One mtime-keyed content-config parse cache per core instance (per project root).
|
|
13
|
+
const parseCache = new Map();
|
|
14
|
+
function entryDeps(over) {
|
|
15
|
+
return {
|
|
16
|
+
fs: over,
|
|
17
|
+
contentDir,
|
|
18
|
+
parseCache,
|
|
19
|
+
componentDirs,
|
|
20
|
+
resolveComponentDefinitions: () => scanComponentDefinitions(over, componentDirs),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const readDeps = entryDeps(fs);
|
|
24
|
+
/** A mutation's result is returned once its changes are committed, whether it reports success or not. */
|
|
25
|
+
async function mutate(operation) {
|
|
26
|
+
if (commit === undefined)
|
|
27
|
+
return operation(fs);
|
|
28
|
+
const staged = createStagedFileSystem(fs);
|
|
29
|
+
const result = await operation(staged);
|
|
30
|
+
await commit(staged.changeset());
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
scanCollections(options) {
|
|
35
|
+
return scanCollections(fs, contentDir, parseCache, { report: options?.report ?? false });
|
|
36
|
+
},
|
|
37
|
+
collectionScanReport,
|
|
38
|
+
scanComponents() {
|
|
39
|
+
return scanComponentDefinitions(fs, componentDirs);
|
|
40
|
+
},
|
|
41
|
+
getEntry(collection, slug) {
|
|
42
|
+
return getEntryOp(readDeps, collection, slug);
|
|
43
|
+
},
|
|
44
|
+
getEntryAsset(collection, slug, assetPath) {
|
|
45
|
+
return getEntryAssetOp(readDeps, collection, slug, assetPath);
|
|
46
|
+
},
|
|
47
|
+
getProjectAsset(assetPath) {
|
|
48
|
+
return getProjectAssetOp(readDeps, assetPath);
|
|
49
|
+
},
|
|
50
|
+
createEntry(input) {
|
|
51
|
+
return mutate(over => createEntryOp(entryDeps(over), input));
|
|
52
|
+
},
|
|
53
|
+
updateEntry(input) {
|
|
54
|
+
return mutate(over => updateEntryOp(entryDeps(over), input));
|
|
55
|
+
},
|
|
56
|
+
deleteEntry(collection, slug) {
|
|
57
|
+
return mutate(over => deleteEntryOp(entryDeps(over), collection, slug));
|
|
58
|
+
},
|
|
59
|
+
renameEntry(collection, from, to) {
|
|
60
|
+
return mutate(over => renameEntryOp(entryDeps(over), collection, from, to));
|
|
61
|
+
},
|
|
62
|
+
addArrayItem(input) {
|
|
63
|
+
return mutate(over => addArrayItemOp(entryDeps(over), input));
|
|
64
|
+
},
|
|
65
|
+
removeArrayItem(input) {
|
|
66
|
+
return mutate(over => removeArrayItemOp(entryDeps(over), input));
|
|
67
|
+
},
|
|
68
|
+
createPage(input) {
|
|
69
|
+
return mutate(over => createPageOp({ fs: over }, input));
|
|
70
|
+
},
|
|
71
|
+
duplicatePage(input) {
|
|
72
|
+
return mutate(over => duplicatePageOp({ fs: over }, input));
|
|
73
|
+
},
|
|
74
|
+
deletePage(input) {
|
|
75
|
+
return mutate(over => deletePageOp({ fs: over }, input));
|
|
76
|
+
},
|
|
77
|
+
getLayouts() {
|
|
78
|
+
return getLayoutsOp({ fs });
|
|
79
|
+
},
|
|
80
|
+
listRedirects() {
|
|
81
|
+
return listRedirectsOp({ fs });
|
|
82
|
+
},
|
|
83
|
+
addRedirect(input) {
|
|
84
|
+
return mutate(over => addRedirectOp({ fs: over }, input));
|
|
85
|
+
},
|
|
86
|
+
updateRedirect(input) {
|
|
87
|
+
return mutate(over => updateRedirectOp({ fs: over }, input));
|
|
88
|
+
},
|
|
89
|
+
deleteRedirect(input) {
|
|
90
|
+
return mutate(over => deleteRedirectOp({ fs: over }, input));
|
|
91
|
+
},
|
|
92
|
+
media: opts.media,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-write-model.d.ts","sourceRoot":"","sources":["../src/editor-write-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAG1E,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,yBAAyB,EACzB,KAAK,eAAe,EACpB,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,eAAe,GACpB,MAAM,oBAAoB,CAAA;AAE3B;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOtF;AAED,iGAAiG;AACjG,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,MAAM,CAAA;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,IAAI,EAAE,cAAc,EACpB,KAAK,GAAE,MAAM,IAAuB,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIzB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM/F;AAED,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAe9H"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the editor actually writes when it creates an entry — the create-route half.
|
|
3
|
+
*
|
|
4
|
+
* The value rules underneath (what a blank field holds, which keys a repeater item carries,
|
|
5
|
+
* which required fields count as unfilled) live in `@nuasite/cms-types` so that every editor
|
|
6
|
+
* can reach them: `collections-admin` and webmaster's own collections panel depend on
|
|
7
|
+
* `cms-client`, which is a sibling of this package, not a consumer. They are re-exported here
|
|
8
|
+
* because the create pipeline reads as one thing.
|
|
9
|
+
*
|
|
10
|
+
* What stays is what only makes sense next to the create route: the form's starting
|
|
11
|
+
* frontmatter, the empty filter the request applies, and the keys the route injects.
|
|
12
|
+
*
|
|
13
|
+
* A check built on a second, drifted copy of any of this reports failures that cannot happen
|
|
14
|
+
* and misses the ones that can — which is why none of it may be reimplemented anywhere.
|
|
15
|
+
*/
|
|
16
|
+
import { blankFieldValue } from '@nuasite/cms-types';
|
|
17
|
+
import { isPlainRecord } from "./shared.js";
|
|
18
|
+
export { blankFieldValue, blankRequiredFields, ENTRY_SLUG_FIELD, isBlankFieldValue, newRepeaterItem, seedValueForRequiredField, withEntrySlug, withoutBlankArrayItems, withRenamedEntrySlug, } from '@nuasite/cms-types';
|
|
19
|
+
/**
|
|
20
|
+
* The frontmatter the editor holds when "create entry" opens, before the user types.
|
|
21
|
+
*
|
|
22
|
+
* `title` is excluded because the create form carries it in its own header field, and
|
|
23
|
+
* hidden fields are excluded because the form cannot fill them in. Neither is missing from
|
|
24
|
+
* the finished entry — see `applyCreateRouteFields`, which is what puts `title` back.
|
|
25
|
+
*
|
|
26
|
+
* The values come from `blankFieldValue`, the same function `draftForCreate` in `cms-client`
|
|
27
|
+
* asks. The two used to seed differently, so this — and the check built on it — described a
|
|
28
|
+
* write only one of the two editors ever made.
|
|
29
|
+
*/
|
|
30
|
+
export function newEntryFrontmatter(fields) {
|
|
31
|
+
const frontmatter = {};
|
|
32
|
+
for (const field of fields) {
|
|
33
|
+
if (field.name === 'title' || field.hidden)
|
|
34
|
+
continue;
|
|
35
|
+
frontmatter[field.name] = blankFieldValue(field);
|
|
36
|
+
}
|
|
37
|
+
return frontmatter;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The last step of a create: what the server adds before the file is written.
|
|
41
|
+
*
|
|
42
|
+
* A markdown entry gets the title from the form — which refuses to be blank — plus today's
|
|
43
|
+
* date, and the form's own frontmatter wins over both (`handlers/api-routes.ts`). A data
|
|
44
|
+
* entry is written verbatim, with the title already among its fields.
|
|
45
|
+
*
|
|
46
|
+
* Anything predicting a create has to apply this. Stopping at the editor's payload predicts
|
|
47
|
+
* an entry with no title, and then reports a required `title` as broken on every project.
|
|
48
|
+
*/
|
|
49
|
+
export function applyCreateRouteFields(frontmatter, kind, today = () => new Date()) {
|
|
50
|
+
const title = 'Untitled';
|
|
51
|
+
if (kind === 'data')
|
|
52
|
+
return { title, ...frontmatter };
|
|
53
|
+
return { title, date: today().toISOString().split('T')[0], ...frontmatter };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* What survives the create request.
|
|
57
|
+
*
|
|
58
|
+
* The editor drops empty strings and `undefined` rather than writing them, so a field
|
|
59
|
+
* the user left alone reaches the schema as *absent*, not as `''`. Anything predicting
|
|
60
|
+
* a create has to apply this — the two produce different validation errors, and only
|
|
61
|
+
* one of them is real.
|
|
62
|
+
*/
|
|
63
|
+
export function omitEmptyOnCreate(frontmatter) {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
66
|
+
if (value !== undefined && value !== '')
|
|
67
|
+
out[key] = value;
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What the create route writes of the frontmatter it receives, whichever editor sent it.
|
|
73
|
+
*
|
|
74
|
+
* Every create form seeds from `blankFieldValue`, so an untouched text field arrives as `''` and
|
|
75
|
+
* an untouched object as `{}`, and not every editor filters them out (`omitEmptyOnCreate` is the
|
|
76
|
+
* in-page editor's). An untouched optional object written as `{}` is rejected by a schema that
|
|
77
|
+
* requires any of its members, and Astro then fails the build for the whole collection.
|
|
78
|
+
*
|
|
79
|
+
* So `''` and `undefined` are dropped at every depth, and an object left with nothing in it is
|
|
80
|
+
* dropped too — unless the schema requires it, in which case it stays `{}` for
|
|
81
|
+
* `blankRequiredFields` to refuse by name. Applied in `createEntry`, and by the content check,
|
|
82
|
+
* which predicts the same write.
|
|
83
|
+
*/
|
|
84
|
+
export function normalizeCreateWrite(fields, frontmatter) {
|
|
85
|
+
const byName = new Map(fields.map(field => [field.name, field]));
|
|
86
|
+
const out = {};
|
|
87
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
88
|
+
if (value === undefined || value === '')
|
|
89
|
+
continue;
|
|
90
|
+
const field = byName.get(key);
|
|
91
|
+
if (!isPlainRecord(value)) {
|
|
92
|
+
out[key] = value;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const members = normalizeCreateWrite(field?.fields ?? [], value);
|
|
96
|
+
if (Object.keys(members).length === 0 && !field?.required)
|
|
97
|
+
continue;
|
|
98
|
+
out[key] = members;
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/fs/glob.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBAET,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAMnE;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8BjD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAcpE"}
|
package/dist/fs/glob.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A directory a glob had to read and could not. Kept apart from every other failure so a
|
|
3
|
+
* caller can report it as a finding and still let a bug (or a path traversal) surface.
|
|
4
|
+
*/
|
|
5
|
+
export class UnreadableDirectoryError extends Error {
|
|
6
|
+
/** Root-relative, forward slashes; the root itself is `.`. */
|
|
7
|
+
directory;
|
|
8
|
+
/** The runtime's error code, e.g. `EACCES`. */
|
|
9
|
+
code;
|
|
10
|
+
constructor(directory, code, options) {
|
|
11
|
+
super(`Cannot read directory "${directory}" (${code})`, options);
|
|
12
|
+
this.name = 'UnreadableDirectoryError';
|
|
13
|
+
this.directory = directory;
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Convert a glob pattern (supports `*`, `**`, `?`, `{a,b}`) to an anchored RegExp. */
|
|
18
|
+
export function globToRegExp(glob) {
|
|
19
|
+
let re = '';
|
|
20
|
+
for (let i = 0; i < glob.length; i++) {
|
|
21
|
+
const c = glob[i];
|
|
22
|
+
if (c === '*') {
|
|
23
|
+
if (glob[i + 1] === '*') {
|
|
24
|
+
re += '.*';
|
|
25
|
+
i++;
|
|
26
|
+
if (glob[i + 1] === '/')
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
re += '[^/]*';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (c === '?') {
|
|
34
|
+
re += '[^/]';
|
|
35
|
+
}
|
|
36
|
+
else if (c === '{') {
|
|
37
|
+
const end = glob.indexOf('}', i);
|
|
38
|
+
if (end === -1) {
|
|
39
|
+
re += '\\{';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const opts = glob.slice(i + 1, end).split(',').map(s => s.replace(/[.+^${}()|[\]\\]/g, '\\$&'));
|
|
43
|
+
re += `(?:${opts.join('|')})`;
|
|
44
|
+
i = end;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if ('.+^$()|[]\\'.includes(c)) {
|
|
48
|
+
re += `\\${c}`;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
re += c;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return new RegExp(`^${re}$`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Whether `glob` could match a file somewhere below the directory `dir` (both root-relative,
|
|
58
|
+
* forward slashes). Errs on the side of yes: only a directory that no path the pattern
|
|
59
|
+
* matches can run through is ruled out.
|
|
60
|
+
*/
|
|
61
|
+
export function globMayMatchUnder(glob, dir) {
|
|
62
|
+
// A brace that spans a slash does not split into segments; do not guess.
|
|
63
|
+
if (/\{[^}]*\//.test(glob))
|
|
64
|
+
return true;
|
|
65
|
+
const segments = glob.split('/').filter(segment => segment !== '' && segment !== '.');
|
|
66
|
+
const dirs = dir.split('/').filter(segment => segment !== '' && segment !== '.');
|
|
67
|
+
const reaches = (i, j) => {
|
|
68
|
+
// Inside `dir`: the pattern has to have a segment left for a file below it.
|
|
69
|
+
if (j === dirs.length)
|
|
70
|
+
return i < segments.length;
|
|
71
|
+
if (i >= segments.length)
|
|
72
|
+
return false;
|
|
73
|
+
// `**` runs through any number of directories.
|
|
74
|
+
if (segments[i].includes('**'))
|
|
75
|
+
return true;
|
|
76
|
+
return globToRegExp(segments[i]).test(dirs[j]) && reaches(i + 1, j + 1);
|
|
77
|
+
};
|
|
78
|
+
return reaches(0, 0);
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fs.d.ts","sourceRoot":"","sources":["../../src/fs/node-fs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AA0I/C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CA6ExD"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { globMayMatchUnder, globToRegExp, UnreadableDirectoryError } from "./glob.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a port-relative (or absolute) path against `root` and ensure it stays
|
|
6
|
+
* within `root`. Mirrors the previous `resolveAndValidatePath` behavior:
|
|
7
|
+
* - absolute filesystem paths under the root pass through;
|
|
8
|
+
* - a project-relative path with a leading slash (e.g. `/src/content/...`) has
|
|
9
|
+
* it stripped before joining with the root;
|
|
10
|
+
* - any path that escapes the root throws.
|
|
11
|
+
*/
|
|
12
|
+
function resolveWithinRoot(root, filePath) {
|
|
13
|
+
const resolvedRoot = path.resolve(root);
|
|
14
|
+
const isAbsoluteFs = filePath.startsWith(resolvedRoot);
|
|
15
|
+
const normalizedPath = (!isAbsoluteFs && filePath.startsWith('/')) ? filePath.slice(1) : filePath;
|
|
16
|
+
const fullPath = path.isAbsolute(normalizedPath) ? path.resolve(normalizedPath) : path.resolve(resolvedRoot, normalizedPath);
|
|
17
|
+
if (!fullPath.startsWith(resolvedRoot + path.sep) && fullPath !== resolvedRoot) {
|
|
18
|
+
throw new Error(`Path traversal detected: ${filePath}`);
|
|
19
|
+
}
|
|
20
|
+
return fullPath;
|
|
21
|
+
}
|
|
22
|
+
function isNodeError(error) {
|
|
23
|
+
return error instanceof Error && 'code' in error;
|
|
24
|
+
}
|
|
25
|
+
/** Is `abs` the directory `root` or below it? Both are real paths. */
|
|
26
|
+
const isWithin = (root, abs) => abs === root || abs.startsWith(root.endsWith(path.sep) ? root : root + path.sep);
|
|
27
|
+
const relativeTo = (absRoot, abs) => path.relative(absRoot, abs).split(path.sep).join('/') || '.';
|
|
28
|
+
/**
|
|
29
|
+
* Recursively list files under `absDir`, returning forward-slash paths relative to the root.
|
|
30
|
+
* A directory that cannot hold anything the caller is after is not entered at all.
|
|
31
|
+
*
|
|
32
|
+
* `linked` holds the real paths of the linked directories on the way down, so that a link
|
|
33
|
+
* back into one of them is entered once and not again.
|
|
34
|
+
*/
|
|
35
|
+
async function walkFiles(walk, absDir, linked) {
|
|
36
|
+
// The tree itself is as large as it is. What links add to it has no such bound: they can
|
|
37
|
+
// lead anywhere, and into each other.
|
|
38
|
+
if (linked.size > 0 && walk.linkedDirectoriesLeft !== undefined && walk.linkedDirectoriesLeft-- <= 0) {
|
|
39
|
+
throw new Error(`More than ${walk.maxLinkedDirectories} directories to list behind symbolic links`);
|
|
40
|
+
}
|
|
41
|
+
let dirEntries;
|
|
42
|
+
try {
|
|
43
|
+
dirEntries = await fs.readdir(absDir, { withFileTypes: true });
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// Only a directory that is not there is an empty one. One that cannot be read
|
|
47
|
+
// (EACCES) must not pass for it: the caller would take its files for absent.
|
|
48
|
+
if (!isNodeError(error))
|
|
49
|
+
throw error;
|
|
50
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
|
|
51
|
+
return [];
|
|
52
|
+
// Named by its root-relative path: the runtime's own message spells out the absolute one.
|
|
53
|
+
throw new UnreadableDirectoryError(relativeTo(walk.absRoot, absDir), error.code ?? 'unknown error', { cause: error });
|
|
54
|
+
}
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const entry of dirEntries) {
|
|
57
|
+
const abs = path.join(absDir, entry.name);
|
|
58
|
+
let isDirectory = entry.isDirectory();
|
|
59
|
+
let isFile = entry.isFile();
|
|
60
|
+
let within = linked;
|
|
61
|
+
let real = null;
|
|
62
|
+
if (walk.followSymlinks && entry.isSymbolicLink()) {
|
|
63
|
+
// A link that leads nowhere is not a file anyone loads.
|
|
64
|
+
const target = await fs.stat(abs).catch(() => null);
|
|
65
|
+
// Without a real path the link is entered as it is: a directory that cannot be read
|
|
66
|
+
// then fails the walk, as it would unlinked.
|
|
67
|
+
real = target?.isDirectory() ? await fs.realpath(abs).catch(() => abs) : null;
|
|
68
|
+
isFile = target?.isFile() ?? false;
|
|
69
|
+
isDirectory = real !== null && !linked.has(real);
|
|
70
|
+
if (real !== null)
|
|
71
|
+
within = new Set([...linked, real]);
|
|
72
|
+
}
|
|
73
|
+
if (isDirectory) {
|
|
74
|
+
// Not walked, so not read either: whatever is in there the caller would discard.
|
|
75
|
+
if (walk.skip(relativeTo(walk.absRoot, abs)))
|
|
76
|
+
continue;
|
|
77
|
+
// Nothing the caller wants can be in a directory its pattern cannot reach, so it is
|
|
78
|
+
// neither read nor, when it cannot be read, a reason to fail.
|
|
79
|
+
if (!walk.mayHold(relativeTo(walk.absRoot, abs)))
|
|
80
|
+
continue;
|
|
81
|
+
// A link out of the project leads into a tree nobody vouched for (the host's own
|
|
82
|
+
// files, on a hosted checkout), so it is not walked. Nor is it skipped: the listing
|
|
83
|
+
// would then pass for whole.
|
|
84
|
+
if (real !== null && !isWithin(walk.realRoot, real)) {
|
|
85
|
+
throw new Error(`Symbolic link "${relativeTo(walk.absRoot, abs)}" leads out of the project root`);
|
|
86
|
+
}
|
|
87
|
+
out.push(...await walkFiles(walk, abs, within));
|
|
88
|
+
}
|
|
89
|
+
else if (isFile) {
|
|
90
|
+
out.push(relativeTo(walk.absRoot, abs));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** The longest leading directory of a glob pattern that contains no glob metacharacters. */
|
|
96
|
+
function staticPrefixDir(pattern) {
|
|
97
|
+
const segments = pattern.split('/');
|
|
98
|
+
const staticSegments = [];
|
|
99
|
+
for (const segment of segments) {
|
|
100
|
+
if (/[*?{}[\]]/.test(segment))
|
|
101
|
+
break;
|
|
102
|
+
staticSegments.push(segment);
|
|
103
|
+
}
|
|
104
|
+
// Drop the last segment if it is the (potentially globbed) file part: a static prefix
|
|
105
|
+
// must be a directory, so only keep segments that precede the first globbed segment.
|
|
106
|
+
if (staticSegments.length === segments.length) {
|
|
107
|
+
staticSegments.pop();
|
|
108
|
+
}
|
|
109
|
+
return staticSegments.join('/');
|
|
110
|
+
}
|
|
111
|
+
/** Write to a unique temp file in the same directory, then rename: a killed write leaves only the temp file, never a half-written target. */
|
|
112
|
+
async function writeAtomically(fullPath, content) {
|
|
113
|
+
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
114
|
+
const tempPath = `${fullPath}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
115
|
+
try {
|
|
116
|
+
await fs.writeFile(tempPath, content);
|
|
117
|
+
await fs.rename(tempPath, fullPath);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
await fs.rm(tempPath, { force: true });
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a `CmsFileSystem` backed by `node:fs`, rooted at `root`.
|
|
126
|
+
* Every path is resolved relative to `root` and validated to stay within it.
|
|
127
|
+
*/
|
|
128
|
+
export function createNodeFs(root) {
|
|
129
|
+
const resolvedRoot = path.resolve(root);
|
|
130
|
+
const resolve = (p) => resolveWithinRoot(resolvedRoot, p);
|
|
131
|
+
return {
|
|
132
|
+
async readFile(filePath) {
|
|
133
|
+
return fs.readFile(resolve(filePath), 'utf-8');
|
|
134
|
+
},
|
|
135
|
+
async readBytes(filePath) {
|
|
136
|
+
return fs.readFile(resolve(filePath));
|
|
137
|
+
},
|
|
138
|
+
async writeFile(filePath, content) {
|
|
139
|
+
await writeAtomically(resolve(filePath), content);
|
|
140
|
+
},
|
|
141
|
+
async writeBytes(filePath, content) {
|
|
142
|
+
await writeAtomically(resolve(filePath), content);
|
|
143
|
+
},
|
|
144
|
+
async rename(from, to) {
|
|
145
|
+
const fullTo = resolve(to);
|
|
146
|
+
await fs.mkdir(path.dirname(fullTo), { recursive: true });
|
|
147
|
+
await fs.rename(resolve(from), fullTo);
|
|
148
|
+
},
|
|
149
|
+
async remove(filePath) {
|
|
150
|
+
await fs.rm(resolve(filePath), { force: true });
|
|
151
|
+
},
|
|
152
|
+
async exists(filePath) {
|
|
153
|
+
try {
|
|
154
|
+
await fs.access(resolve(filePath));
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
async list(dir) {
|
|
162
|
+
try {
|
|
163
|
+
const entries = await fs.readdir(resolve(dir), { withFileTypes: true });
|
|
164
|
+
return entries.map(entry => ({ name: entry.name, isDirectory: entry.isDirectory() }));
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (isNodeError(error) && error.code === 'ENOENT')
|
|
168
|
+
return [];
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
async glob(pattern, options) {
|
|
173
|
+
const baseRel = staticPrefixDir(pattern);
|
|
174
|
+
const absBase = resolve(baseRel);
|
|
175
|
+
const matcher = globToRegExp(pattern);
|
|
176
|
+
const followSymlinks = options?.followSymlinks ?? false;
|
|
177
|
+
const walk = {
|
|
178
|
+
absRoot: resolvedRoot,
|
|
179
|
+
mayHold: dir => globMayMatchUnder(pattern, dir),
|
|
180
|
+
skip: options?.skipDirectory ?? (() => false),
|
|
181
|
+
followSymlinks,
|
|
182
|
+
// The root may itself sit behind a link (a temporary directory on macOS does).
|
|
183
|
+
realRoot: followSymlinks ? await fs.realpath(resolvedRoot).catch(() => resolvedRoot) : resolvedRoot,
|
|
184
|
+
maxLinkedDirectories: options?.maxLinkedDirectories,
|
|
185
|
+
linkedDirectoriesLeft: options?.maxLinkedDirectories,
|
|
186
|
+
};
|
|
187
|
+
// Asked of the starting directory as of any other, so that one the pattern cannot match
|
|
188
|
+
// under is not read, and not a reason to fail when it cannot be.
|
|
189
|
+
if (!walk.mayHold(relativeTo(resolvedRoot, absBase)))
|
|
190
|
+
return [];
|
|
191
|
+
const files = await walkFiles(walk, absBase, new Set());
|
|
192
|
+
return files.filter(rel => matcher.test(rel));
|
|
193
|
+
},
|
|
194
|
+
async stat(filePath) {
|
|
195
|
+
const s = await fs.stat(resolve(filePath));
|
|
196
|
+
return { mtimeMs: s.mtimeMs, size: s.size };
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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