@slicemachine/plugin-kit 0.4.83-alpha.jp-allow-slice-index-generation.4 → 0.4.83-alpha.jp-allow-slice-index-generation.5
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/createSliceMachineActions.cjs +0 -5
- package/dist/createSliceMachineActions.cjs.map +1 -1
- package/dist/createSliceMachineActions.d.ts +0 -2
- package/dist/createSliceMachineActions.js +0 -5
- package/dist/createSliceMachineActions.js.map +1 -1
- package/dist/createSliceMachinePluginRunner.cjs +0 -1
- package/dist/createSliceMachinePluginRunner.cjs.map +1 -1
- package/dist/createSliceMachinePluginRunner.js +0 -1
- package/dist/createSliceMachinePluginRunner.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/types.cjs +0 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/createSliceMachineActions.ts +0 -12
- package/src/createSliceMachinePluginRunner.ts +0 -1
- package/src/index.ts +0 -7
- package/src/types.ts +0 -3
- package/dist/hooks/sliceLibrary-update.d.ts +0 -25
- package/src/hooks/sliceLibrary-update.ts +0 -38
|
@@ -66,11 +66,6 @@ class SliceMachineActions {
|
|
|
66
66
|
}
|
|
67
67
|
return library;
|
|
68
68
|
});
|
|
69
|
-
__publicField(this, "updateSliceLibrary", async (args) => {
|
|
70
|
-
await this._hookSystem.callHook("slice-library:update", {
|
|
71
|
-
libraryID: args.libraryID
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
69
|
__publicField(this, "readAllCustomTypeModels", async () => {
|
|
75
70
|
const { ids } = await this.readCustomTypeLibrary();
|
|
76
71
|
return await Promise.all(ids.map(async (id) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachineActions.cjs","sources":["../../src/createSliceMachineActions.ts"],"sourcesContent":["import { HookSystem } from \"./lib/HookSystem\";\nimport { SliceMachineHooks, SliceMachineProject } from \"./types\";\n\nimport { CustomTypeLibraryReadHookReturnType } from \"./hooks/customTypeLibrary-read\";\nimport {\n\tCustomTypeReadHookData,\n\tCustomTypeReadHookReturnType,\n} from \"./hooks/customType-read\";\nimport {\n\tSliceLibraryReadHookData,\n\tSliceLibraryReadHookReturnType,\n} from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookData, SliceReadHookReturnType } from \"./hooks/slice-read\";\
|
|
1
|
+
{"version":3,"file":"createSliceMachineActions.cjs","sources":["../../src/createSliceMachineActions.ts"],"sourcesContent":["import { HookSystem } from \"./lib/HookSystem\";\nimport { SliceMachineHooks, SliceMachineProject } from \"./types\";\n\nimport { CustomTypeLibraryReadHookReturnType } from \"./hooks/customTypeLibrary-read\";\nimport {\n\tCustomTypeReadHookData,\n\tCustomTypeReadHookReturnType,\n} from \"./hooks/customType-read\";\nimport {\n\tSliceLibraryReadHookData,\n\tSliceLibraryReadHookReturnType,\n} from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookData, SliceReadHookReturnType } from \"./hooks/slice-read\";\n\nexport type ReadAllSliceModelsActionArgs<\n\tTWithMetadata extends boolean = false,\n> = {\n\twithMetadata?: TWithMetadata;\n};\n\nexport type ReadAllSliceModelsActionReturnType = (SliceReadHookReturnType & {\n\tlibraryID: string;\n})[];\n\nexport type ReadAllSliceModelsForLibraryActionArgs = {\n\tlibraryID: string;\n};\n\n/**\n * Creates Slice Machine actions.\n *\n * @internal\n */\nexport const createSliceMachineActions = (\n\tproject: SliceMachineProject,\n\thookSystem: HookSystem<SliceMachineHooks>,\n): SliceMachineActions => {\n\treturn new SliceMachineActions(project, hookSystem);\n};\n\n/**\n * Slice Machine actions shared to plugins and hooks.\n */\nexport class SliceMachineActions {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\t/**\n\t * The actions' hook system used to internally trigger hook calls.\n\t *\n\t * @internal\n\t */\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\n\tconstructor(\n\t\tproject: SliceMachineProject,\n\t\thookSystem: HookSystem<SliceMachineHooks>,\n\t) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t}\n\n\treadAllSliceModels =\n\t\tasync (): Promise<ReadAllSliceModelsActionReturnType> => {\n\t\t\tconst libraryIDs = this._project.config.libraries || [];\n\n\t\t\treturn (\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tlibraryIDs.map(async (libraryID) => {\n\t\t\t\t\t\tconst models = await this.readAllSliceModelsForLibrary({\n\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn models.map((model) => {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t...model,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t).flat();\n\t\t};\n\n\treadAllSliceModelsForLibrary = async (\n\t\targs: ReadAllSliceModelsForLibraryActionArgs,\n\t): Promise<SliceReadHookReturnType[]> => {\n\t\tconst { sliceIDs } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\treturn await Promise.all(\n\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\treturn await this.readSliceModel({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\t};\n\n\treadSliceModel = async (\n\t\targs: SliceReadHookData,\n\t): Promise<SliceReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(\n\t\t\t\t`Slice \\`${args.sliceID}\\` not found in the \\`${args.libraryID}\\` library.`,\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadSliceLibrary = async (\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SliceLibraryReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [library],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice-library:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\tif (!library) {\n\t\t\tthrow new Error(`Slice library \\`${args.libraryID}\\` not found.`, {\n\t\t\t\tcause,\n\t\t\t});\n\t\t}\n\n\t\treturn library;\n\t};\n\n\treadAllCustomTypeModels = async (): Promise<\n\t\tCustomTypeReadHookReturnType[]\n\t> => {\n\t\tconst { ids } = await this.readCustomTypeLibrary();\n\n\t\treturn await Promise.all(\n\t\t\tids.map(async (id) => {\n\t\t\t\treturn this.readCustomTypeModel({ id });\n\t\t\t}),\n\t\t);\n\t};\n\n\treadCustomTypeModel = async (\n\t\targs: CustomTypeReadHookData,\n\t): Promise<CustomTypeReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"custom-type:read\", {\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(`Custom type \\`${args.id}\\` not found.`, { cause });\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadCustomTypeLibrary =\n\t\tasync (): Promise<CustomTypeLibraryReadHookReturnType> => {\n\t\t\tconst {\n\t\t\t\tdata: [library],\n\t\t\t\terrors: [cause],\n\t\t\t} = await this._hookSystem.callHook(\n\t\t\t\t\"custom-type-library:read\",\n\t\t\t\tundefined,\n\t\t\t);\n\n\t\t\tif (!library) {\n\t\t\t\tthrow new Error(`Couldn't read custom type library.`, {\n\t\t\t\t\tcause,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn library;\n\t\t};\n}\n"],"names":[],"mappings":";;;;;AAiCO,MAAM,4BAA4B,CACx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,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,sBAAsB;AAAA,QACzD,WAAW,KAAK;AAAA,MAAA,CAChB;AAED,UAAI,CAAC,SAAS;AACb,cAAM,IAAI,MAAM,mBAAmB,KAAK,SAAS,iBAAiB;AAAA,UACjE;AAAA,QAAA,CACA;AAAA,MACF;AAEA,aAAO;AAAA,IACR;AAEA,mDAA0B,YAEtB;AACH,YAAM,EAAE,IAAA,IAAQ,MAAM,KAAK,sBAAA;AAE3B,aAAO,MAAM,QAAQ,IACpB,IAAI,IAAI,OAAO,OAAM;AACpB,eAAO,KAAK,oBAAoB,EAAE,IAAI;AAAA,MACvC,CAAC,CAAC;AAAA,IAEJ;AAEA,+CAAsB,OACrB,SAC0C;AAC1C,YAAM,EACL,MAAM,CAAC,KAAK,GACZ,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,oBAAoB;AAAA,QACvD,IAAI,KAAK;AAAA,MAAA,CACT;AAED,UAAI,CAAC,OAAO;AACX,cAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE,iBAAiB,EAAE,OAAO;AAAA,MACnE;AAEA,aAAO;AAAA,IACR;AAEA,iDACC,YAAyD;AACxD,YAAM,EACL,MAAM,CAAC,OAAO,GACd,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAC1B,4BACA,MAAS;AAGV,UAAI,CAAC,SAAS;AACb,cAAM,IAAI,MAAM,sCAAsC;AAAA,UACrD;AAAA,QAAA,CACA;AAAA,MACF;AAEA,aAAO;AAAA,IACR;AAjIA,SAAK,WAAW;AAChB,SAAK,cAAc;AAAA,EACpB;AAgIA;;;"}
|
|
@@ -4,7 +4,6 @@ import { CustomTypeLibraryReadHookReturnType } from "./hooks/customTypeLibrary-r
|
|
|
4
4
|
import { CustomTypeReadHookData, CustomTypeReadHookReturnType } from "./hooks/customType-read";
|
|
5
5
|
import { SliceLibraryReadHookData, SliceLibraryReadHookReturnType } from "./hooks/sliceLibrary-read";
|
|
6
6
|
import { SliceReadHookData, SliceReadHookReturnType } from "./hooks/slice-read";
|
|
7
|
-
import { SliceLibraryUpdateHookData, SliceLibraryUpdateHookReturnType } from "./hooks/sliceLibrary-update";
|
|
8
7
|
export type ReadAllSliceModelsActionArgs<TWithMetadata extends boolean = false> = {
|
|
9
8
|
withMetadata?: TWithMetadata;
|
|
10
9
|
};
|
|
@@ -41,7 +40,6 @@ export declare class SliceMachineActions {
|
|
|
41
40
|
readAllSliceModelsForLibrary: (args: ReadAllSliceModelsForLibraryActionArgs) => Promise<SliceReadHookReturnType[]>;
|
|
42
41
|
readSliceModel: (args: SliceReadHookData) => Promise<SliceReadHookReturnType>;
|
|
43
42
|
readSliceLibrary: (args: SliceLibraryReadHookData) => Promise<SliceLibraryReadHookReturnType>;
|
|
44
|
-
updateSliceLibrary: (args: SliceLibraryUpdateHookData) => Promise<SliceLibraryUpdateHookReturnType>;
|
|
45
43
|
readAllCustomTypeModels: () => Promise<CustomTypeReadHookReturnType[]>;
|
|
46
44
|
readCustomTypeModel: (args: CustomTypeReadHookData) => Promise<CustomTypeReadHookReturnType>;
|
|
47
45
|
readCustomTypeLibrary: () => Promise<CustomTypeLibraryReadHookReturnType>;
|
|
@@ -64,11 +64,6 @@ class SliceMachineActions {
|
|
|
64
64
|
}
|
|
65
65
|
return library;
|
|
66
66
|
});
|
|
67
|
-
__publicField(this, "updateSliceLibrary", async (args) => {
|
|
68
|
-
await this._hookSystem.callHook("slice-library:update", {
|
|
69
|
-
libraryID: args.libraryID
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
67
|
__publicField(this, "readAllCustomTypeModels", async () => {
|
|
73
68
|
const { ids } = await this.readCustomTypeLibrary();
|
|
74
69
|
return await Promise.all(ids.map(async (id) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachineActions.js","sources":["../../src/createSliceMachineActions.ts"],"sourcesContent":["import { HookSystem } from \"./lib/HookSystem\";\nimport { SliceMachineHooks, SliceMachineProject } from \"./types\";\n\nimport { CustomTypeLibraryReadHookReturnType } from \"./hooks/customTypeLibrary-read\";\nimport {\n\tCustomTypeReadHookData,\n\tCustomTypeReadHookReturnType,\n} from \"./hooks/customType-read\";\nimport {\n\tSliceLibraryReadHookData,\n\tSliceLibraryReadHookReturnType,\n} from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookData, SliceReadHookReturnType } from \"./hooks/slice-read\";\
|
|
1
|
+
{"version":3,"file":"createSliceMachineActions.js","sources":["../../src/createSliceMachineActions.ts"],"sourcesContent":["import { HookSystem } from \"./lib/HookSystem\";\nimport { SliceMachineHooks, SliceMachineProject } from \"./types\";\n\nimport { CustomTypeLibraryReadHookReturnType } from \"./hooks/customTypeLibrary-read\";\nimport {\n\tCustomTypeReadHookData,\n\tCustomTypeReadHookReturnType,\n} from \"./hooks/customType-read\";\nimport {\n\tSliceLibraryReadHookData,\n\tSliceLibraryReadHookReturnType,\n} from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookData, SliceReadHookReturnType } from \"./hooks/slice-read\";\n\nexport type ReadAllSliceModelsActionArgs<\n\tTWithMetadata extends boolean = false,\n> = {\n\twithMetadata?: TWithMetadata;\n};\n\nexport type ReadAllSliceModelsActionReturnType = (SliceReadHookReturnType & {\n\tlibraryID: string;\n})[];\n\nexport type ReadAllSliceModelsForLibraryActionArgs = {\n\tlibraryID: string;\n};\n\n/**\n * Creates Slice Machine actions.\n *\n * @internal\n */\nexport const createSliceMachineActions = (\n\tproject: SliceMachineProject,\n\thookSystem: HookSystem<SliceMachineHooks>,\n): SliceMachineActions => {\n\treturn new SliceMachineActions(project, hookSystem);\n};\n\n/**\n * Slice Machine actions shared to plugins and hooks.\n */\nexport class SliceMachineActions {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\t/**\n\t * The actions' hook system used to internally trigger hook calls.\n\t *\n\t * @internal\n\t */\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\n\tconstructor(\n\t\tproject: SliceMachineProject,\n\t\thookSystem: HookSystem<SliceMachineHooks>,\n\t) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t}\n\n\treadAllSliceModels =\n\t\tasync (): Promise<ReadAllSliceModelsActionReturnType> => {\n\t\t\tconst libraryIDs = this._project.config.libraries || [];\n\n\t\t\treturn (\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tlibraryIDs.map(async (libraryID) => {\n\t\t\t\t\t\tconst models = await this.readAllSliceModelsForLibrary({\n\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn models.map((model) => {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tlibraryID,\n\t\t\t\t\t\t\t\t...model,\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t).flat();\n\t\t};\n\n\treadAllSliceModelsForLibrary = async (\n\t\targs: ReadAllSliceModelsForLibraryActionArgs,\n\t): Promise<SliceReadHookReturnType[]> => {\n\t\tconst { sliceIDs } = await this.readSliceLibrary({\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\treturn await Promise.all(\n\t\t\tsliceIDs.map(async (sliceID) => {\n\t\t\t\treturn await this.readSliceModel({\n\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\tsliceID,\n\t\t\t\t});\n\t\t\t}),\n\t\t);\n\t};\n\n\treadSliceModel = async (\n\t\targs: SliceReadHookData,\n\t): Promise<SliceReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t\tsliceID: args.sliceID,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(\n\t\t\t\t`Slice \\`${args.sliceID}\\` not found in the \\`${args.libraryID}\\` library.`,\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadSliceLibrary = async (\n\t\targs: SliceLibraryReadHookData,\n\t): Promise<SliceLibraryReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [library],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"slice-library:read\", {\n\t\t\tlibraryID: args.libraryID,\n\t\t});\n\n\t\tif (!library) {\n\t\t\tthrow new Error(`Slice library \\`${args.libraryID}\\` not found.`, {\n\t\t\t\tcause,\n\t\t\t});\n\t\t}\n\n\t\treturn library;\n\t};\n\n\treadAllCustomTypeModels = async (): Promise<\n\t\tCustomTypeReadHookReturnType[]\n\t> => {\n\t\tconst { ids } = await this.readCustomTypeLibrary();\n\n\t\treturn await Promise.all(\n\t\t\tids.map(async (id) => {\n\t\t\t\treturn this.readCustomTypeModel({ id });\n\t\t\t}),\n\t\t);\n\t};\n\n\treadCustomTypeModel = async (\n\t\targs: CustomTypeReadHookData,\n\t): Promise<CustomTypeReadHookReturnType> => {\n\t\tconst {\n\t\t\tdata: [model],\n\t\t\terrors: [cause],\n\t\t} = await this._hookSystem.callHook(\"custom-type:read\", {\n\t\t\tid: args.id,\n\t\t});\n\n\t\tif (!model) {\n\t\t\tthrow new Error(`Custom type \\`${args.id}\\` not found.`, { cause });\n\t\t}\n\n\t\treturn model;\n\t};\n\n\treadCustomTypeLibrary =\n\t\tasync (): Promise<CustomTypeLibraryReadHookReturnType> => {\n\t\t\tconst {\n\t\t\t\tdata: [library],\n\t\t\t\terrors: [cause],\n\t\t\t} = await this._hookSystem.callHook(\n\t\t\t\t\"custom-type-library:read\",\n\t\t\t\tundefined,\n\t\t\t);\n\n\t\t\tif (!library) {\n\t\t\t\tthrow new Error(`Couldn't read custom type library.`, {\n\t\t\t\t\tcause,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn library;\n\t\t};\n}\n"],"names":[],"mappings":";;;AAiCO,MAAM,4BAA4B,CACxC,SACA,eACwB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MAAM,KAAK,YAAY,SAAS,sBAAsB;AAAA,QACzD,WAAW,KAAK;AAAA,MAAA,CAChB;AAED,UAAI,CAAC,SAAS;AACb,cAAM,IAAI,MAAM,mBAAmB,KAAK,SAAS,iBAAiB;AAAA,UACjE;AAAA,QAAA,CACA;AAAA,MACF;AAEA,aAAO;AAAA,IACR;AAEA,mDAA0B,YAEtB;AACH,YAAM,EAAE,IAAA,IAAQ,MAAM,KAAK,sBAAA;AAE3B,aAAO,MAAM,QAAQ,IACpB,IAAI,IAAI,OAAO,OAAM;AACpB,eAAO,KAAK,oBAAoB,EAAE,IAAI;AAAA,MACvC,CAAC,CAAC;AAAA,IAEJ;AAEA,+CAAsB,OACrB,SAC0C;AAC1C,YAAM,EACL,MAAM,CAAC,KAAK,GACZ,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAAS,oBAAoB;AAAA,QACvD,IAAI,KAAK;AAAA,MAAA,CACT;AAED,UAAI,CAAC,OAAO;AACX,cAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE,iBAAiB,EAAE,OAAO;AAAA,MACnE;AAEA,aAAO;AAAA,IACR;AAEA,iDACC,YAAyD;AACxD,YAAM,EACL,MAAM,CAAC,OAAO,GACd,QAAQ,CAAC,KAAK,EAAA,IACX,MAAM,KAAK,YAAY,SAC1B,4BACA,MAAS;AAGV,UAAI,CAAC,SAAS;AACb,cAAM,IAAI,MAAM,sCAAsC;AAAA,UACrD;AAAA,QAAA,CACA;AAAA,MACF;AAEA,aAAO;AAAA,IACR;AAjIA,SAAK,WAAW;AAChB,SAAK,cAAc;AAAA,EACpB;AAgIA;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachinePluginRunner.cjs","sources":["../../src/createSliceMachinePluginRunner.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport _module, { createRequire } from \"node:module\";\n\nimport { defu } from \"defu\";\n\nimport { HookSystem } from \"./lib/HookSystem\";\nimport { createSliceMachineContext } from \"./createSliceMachineContext\";\nimport {\n\tLoadedSliceMachinePlugin,\n\tSliceMachinePlugin,\n} from \"./defineSliceMachinePlugin\";\nimport {\n\tSliceMachineConfigPluginRegistration,\n\tSliceMachineHookExtraArgs,\n\tSliceMachineHookTypes,\n\tSliceMachineHooks,\n\tSliceMachineProject,\n} from \"./types\";\nimport { createSliceMachineHookSystem } from \"./createSliceMachineHookSystem\";\nimport {\n\tcreateSliceMachineActions,\n\tSliceMachineActions,\n} from \"./createSliceMachineActions\";\nimport {\n\tcreateSliceMachineHelpers,\n\tSliceMachineHelpers,\n} from \"./createSliceMachineHelpers\";\n\n/**\n * @internal\n */\nexport const REQUIRED_ADAPTER_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:create\",\n\t\"slice:read\",\n\t\"slice:rename\",\n\t\"slice:delete\",\n\t\"slice:update\",\n\t\"slice:asset:update\",\n\t\"slice:asset:read\",\n\t\"slice:asset:delete\",\n\t\"slice-library:read\",\n\t\"slice-library:update\",\n\t\"custom-type:create\",\n\t\"custom-type:read\",\n\t\"custom-type:rename\",\n\t\"custom-type:delete\",\n\t\"custom-type:update\",\n\t\"custom-type:asset:update\",\n\t\"custom-type:asset:read\",\n\t\"custom-type:asset:delete\",\n\t\"custom-type-library:read\",\n];\n/**\n * @internal\n */\nexport const ADAPTER_ONLY_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:read\",\n\t\"slice:asset:read\",\n\t\"slice-library:read\",\n\t\"custom-type:read\",\n\t\"custom-type:asset:read\",\n\t\"custom-type-library:read\",\n\t\"project:environment:read\",\n];\n\ntype SliceMachinePluginRunnerConstructorArgs = {\n\tproject: SliceMachineProject;\n\thookSystem: HookSystem<SliceMachineHooks>;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport class SliceMachinePluginRunner {\n\tprivate _project: SliceMachineProject;\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\tprivate _nativePlugins: Record<string, SliceMachinePlugin>;\n\n\t/**\n\t * Slice Machine actions provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawActions`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawActions: SliceMachineActions;\n\n\t/**\n\t * Slice Machine helpers provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawHelpers`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawHelpers: SliceMachineHelpers;\n\n\t// Methods forwarded to the plugin runner's hook system.\n\tcallHook: HookSystem<SliceMachineHooks>[\"callHook\"];\n\thooksForOwner: HookSystem<SliceMachineHooks>[\"hooksForOwner\"];\n\thooksForType: HookSystem<SliceMachineHooks>[\"hooksForType\"];\n\tcreateScope: HookSystem<SliceMachineHooks>[\"createScope\"];\n\n\tconstructor({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins = {},\n\t}: SliceMachinePluginRunnerConstructorArgs) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t\tthis._nativePlugins = nativePlugins;\n\n\t\tthis.rawActions = createSliceMachineActions(\n\t\t\tthis._project,\n\t\t\tthis._hookSystem,\n\t\t);\n\t\tthis.rawHelpers = createSliceMachineHelpers(this._project);\n\n\t\tthis.callHook = this._hookSystem.callHook.bind(this._hookSystem);\n\t\tthis.hooksForOwner = this._hookSystem.hooksForOwner.bind(this._hookSystem);\n\t\tthis.hooksForType = this._hookSystem.hooksForType.bind(this._hookSystem);\n\t\tthis.createScope = this._hookSystem.createScope.bind(this._hookSystem);\n\t}\n\n\tprivate async _loadPlugin(\n\t\tpluginRegistration: SliceMachineConfigPluginRegistration,\n\t): Promise<LoadedSliceMachinePlugin> {\n\t\t// Sanitize registration\n\t\tconst { resolve, options = {} } =\n\t\t\ttypeof pluginRegistration === \"object\" && \"resolve\" in pluginRegistration\n\t\t\t\t? pluginRegistration\n\t\t\t\t: { resolve: pluginRegistration };\n\n\t\tlet plugin: SliceMachinePlugin | undefined = undefined;\n\n\t\tif (typeof resolve === \"string\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\ttry {\n\t\t\t\tconst noop = path.resolve(this._project.root, \"noop.js\");\n\n\t\t\t\tlet resolvedID = resolve;\n\n\t\t\t\t// Support Yarn PnP\n\t\t\t\tif (\n\t\t\t\t\tprocess.versions.pnp &&\n\t\t\t\t\t\"findPnpApi\" in _module &&\n\t\t\t\t\ttypeof _module.findPnpApi === \"function\"\n\t\t\t\t) {\n\t\t\t\t\tconst pnpApi = _module.findPnpApi(noop);\n\t\t\t\t\tif (pnpApi) {\n\t\t\t\t\t\tresolvedID = pnpApi.resolveRequest(resolve, noop);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst raw = await createRequire(noop)(resolvedID);\n\t\t\t\tplugin = raw.default || raw;\n\t\t\t} catch (error) {\n\t\t\t\t// Only log in development, but not during tests when a native plugin matches.\n\t\t\t\tif (\n\t\t\t\t\timport.meta.env.DEV &&\n\t\t\t\t\t!(import.meta.env.TEST && resolve in this._nativePlugins)\n\t\t\t\t) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\t// If an installed plugin cannot be resolved, try loading a native plugin.\n\t\t\t\tplugin = this._nativePlugins[resolve];\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not resolve plugin \\`${resolve}\\`. Check that it has been installed.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tplugin = resolve;\n\t\t}\n\n\t\tif (!plugin) {\n\t\t\tthrow new Error(`Could not load plugin: \\`${resolve}\\``);\n\t\t}\n\n\t\tconst mergedOptions = defu(options, plugin.defaultOptions || {});\n\n\t\treturn {\n\t\t\t...plugin,\n\t\t\tresolve,\n\t\t\toptions: mergedOptions,\n\t\t};\n\t}\n\n\tprivate async _setupPlugin(\n\t\tplugin: LoadedSliceMachinePlugin,\n\t\tas: \"adapter\" | \"plugin\",\n\t): Promise<void> {\n\t\tconst context = createSliceMachineContext({\n\t\t\tactions: this.rawActions,\n\t\t\thelpers: this.rawHelpers,\n\t\t\tproject: this._project,\n\t\t\tplugin,\n\t\t});\n\t\tconst hookSystemScope =\n\t\t\tthis._hookSystem.createScope<SliceMachineHookExtraArgs>(\n\t\t\t\tplugin.meta.name,\n\t\t\t\t[context],\n\t\t\t);\n\n\t\t// Prevent plugins from hooking to adapter only hooks\n\t\tconst hook: typeof hookSystemScope.hook =\n\t\t\tas === \"adapter\"\n\t\t\t\t? hookSystemScope.hook\n\t\t\t\t: (type, hook, ...args) => {\n\t\t\t\t\t\tif (ADAPTER_ONLY_HOOKS.includes(type)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn hookSystemScope.hook(type, hook, ...args);\n\t\t\t\t };\n\n\t\t// Run plugin setup with actions and context\n\t\ttry {\n\t\t\tawait plugin.setup({\n\t\t\t\t...context,\n\t\t\t\thook,\n\t\t\t\tunhook: hookSystemScope.unhook,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error.message}`,\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _validateAdapter(adapter: LoadedSliceMachinePlugin): void {\n\t\tconst hooks = this._hookSystem.hooksForOwner(adapter.meta.name);\n\t\tconst hookTypes = hooks.map((hook) => hook.meta.type);\n\n\t\tconst missingHooks = REQUIRED_ADAPTER_HOOKS.filter(\n\t\t\t(requiredHookType) => !hookTypes.includes(requiredHookType),\n\t\t);\n\n\t\tif (missingHooks.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Adapter \\`${\n\t\t\t\t\tadapter.meta.name\n\t\t\t\t}\\` is missing hooks: \\`${missingHooks.join(\"`, `\")}\\``,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync init(): Promise<void> {\n\t\tconst [adapter, ...plugins] = await Promise.all(\n\t\t\t[\n\t\t\t\tthis._project.config.adapter,\n\t\t\t\t...(this._project.config.plugins ?? []),\n\t\t\t].map((pluginRegistration) => this._loadPlugin(pluginRegistration)),\n\t\t);\n\n\t\tawait Promise.all([\n\t\t\tthis._setupPlugin(adapter, \"adapter\"),\n\t\t\t...plugins.map((plugin) => this._setupPlugin(plugin, \"plugin\")),\n\t\t]);\n\n\t\tthis._validateAdapter(adapter);\n\t}\n}\n\ntype CreateSliceMachinePluginRunnerArgs = {\n\tproject: SliceMachineProject;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport const createSliceMachinePluginRunner = ({\n\tproject,\n\tnativePlugins,\n}: CreateSliceMachinePluginRunnerArgs): SliceMachinePluginRunner => {\n\tconst hookSystem = createSliceMachineHookSystem();\n\n\treturn new SliceMachinePluginRunner({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins,\n\t});\n};\n"],"names":["createSliceMachineActions","createSliceMachineHelpers","path","createRequire","defu","createSliceMachineContext","hook","createSliceMachineHookSystem"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,MAAM,yBAAkD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKM,MAAM,qBAA8C;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;MAY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AAK,YAAY,cAAc,QAAQ,KAAK,IAAI;AAC9D,UAAM,YAAY,MAAM,IAAI,CAAC,SAAS,KAAK,KAAK,IAAI;AAEpD,UAAM,eAAe,uBAAuB,OAC3C,CAAC,qBAAqB,CAAC,UAAU,SAAS,gBAAgB,CAAC;AAG5D,QAAI,aAAa,QAAQ;AACxB,YAAM,IAAI,MACT,aACC,QAAQ,KAAK,IACd,0BAA0B,aAAa,KAAK,MAAM,CAAC,IAAI;AAAA,IAEzD;AAAA,EACD;AAAA,EAEA,MAAM,OAAI;AACT,UAAM,CAAC,SAAS,GAAG,OAAO,IAAI,MAAM,QAAQ,IAC3C;AAAA,MACC,KAAK,SAAS,OAAO;AAAA,MACrB,GAAI,KAAK,SAAS,OAAO,WAAW,CAAA;AAAA,IAAA,EACnC,IAAI,CAAC,uBAAuB,KAAK,YAAY,kBAAkB,CAAC,CAAC;AAGpE,UAAM,QAAQ,IAAI;AAAA,MACjB,KAAK,aAAa,SAAS,SAAS;AAAA,MACpC,GAAG,QAAQ,IAAI,CAAC,WAAW,KAAK,aAAa,QAAQ,QAAQ,CAAC;AAAA,IAAA,CAC9D;AAED,SAAK,iBAAiB,OAAO;AAAA,EAC9B;AACA;AAUM,MAAM,iCAAiC,CAAC,EAC9C,SACA,oBACkE;AAClE,QAAM,aAAaC,6BAAAA,6BAAA;AAEnB,SAAO,IAAI,yBAAyB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AACF;;;;;"}
|
|
1
|
+
{"version":3,"file":"createSliceMachinePluginRunner.cjs","sources":["../../src/createSliceMachinePluginRunner.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport _module, { createRequire } from \"node:module\";\n\nimport { defu } from \"defu\";\n\nimport { HookSystem } from \"./lib/HookSystem\";\nimport { createSliceMachineContext } from \"./createSliceMachineContext\";\nimport {\n\tLoadedSliceMachinePlugin,\n\tSliceMachinePlugin,\n} from \"./defineSliceMachinePlugin\";\nimport {\n\tSliceMachineConfigPluginRegistration,\n\tSliceMachineHookExtraArgs,\n\tSliceMachineHookTypes,\n\tSliceMachineHooks,\n\tSliceMachineProject,\n} from \"./types\";\nimport { createSliceMachineHookSystem } from \"./createSliceMachineHookSystem\";\nimport {\n\tcreateSliceMachineActions,\n\tSliceMachineActions,\n} from \"./createSliceMachineActions\";\nimport {\n\tcreateSliceMachineHelpers,\n\tSliceMachineHelpers,\n} from \"./createSliceMachineHelpers\";\n\n/**\n * @internal\n */\nexport const REQUIRED_ADAPTER_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:create\",\n\t\"slice:read\",\n\t\"slice:rename\",\n\t\"slice:delete\",\n\t\"slice:update\",\n\t\"slice:asset:update\",\n\t\"slice:asset:read\",\n\t\"slice:asset:delete\",\n\t\"slice-library:read\",\n\t\"custom-type:create\",\n\t\"custom-type:read\",\n\t\"custom-type:rename\",\n\t\"custom-type:delete\",\n\t\"custom-type:update\",\n\t\"custom-type:asset:update\",\n\t\"custom-type:asset:read\",\n\t\"custom-type:asset:delete\",\n\t\"custom-type-library:read\",\n];\n/**\n * @internal\n */\nexport const ADAPTER_ONLY_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:read\",\n\t\"slice:asset:read\",\n\t\"slice-library:read\",\n\t\"custom-type:read\",\n\t\"custom-type:asset:read\",\n\t\"custom-type-library:read\",\n\t\"project:environment:read\",\n];\n\ntype SliceMachinePluginRunnerConstructorArgs = {\n\tproject: SliceMachineProject;\n\thookSystem: HookSystem<SliceMachineHooks>;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport class SliceMachinePluginRunner {\n\tprivate _project: SliceMachineProject;\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\tprivate _nativePlugins: Record<string, SliceMachinePlugin>;\n\n\t/**\n\t * Slice Machine actions provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawActions`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawActions: SliceMachineActions;\n\n\t/**\n\t * Slice Machine helpers provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawHelpers`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawHelpers: SliceMachineHelpers;\n\n\t// Methods forwarded to the plugin runner's hook system.\n\tcallHook: HookSystem<SliceMachineHooks>[\"callHook\"];\n\thooksForOwner: HookSystem<SliceMachineHooks>[\"hooksForOwner\"];\n\thooksForType: HookSystem<SliceMachineHooks>[\"hooksForType\"];\n\tcreateScope: HookSystem<SliceMachineHooks>[\"createScope\"];\n\n\tconstructor({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins = {},\n\t}: SliceMachinePluginRunnerConstructorArgs) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t\tthis._nativePlugins = nativePlugins;\n\n\t\tthis.rawActions = createSliceMachineActions(\n\t\t\tthis._project,\n\t\t\tthis._hookSystem,\n\t\t);\n\t\tthis.rawHelpers = createSliceMachineHelpers(this._project);\n\n\t\tthis.callHook = this._hookSystem.callHook.bind(this._hookSystem);\n\t\tthis.hooksForOwner = this._hookSystem.hooksForOwner.bind(this._hookSystem);\n\t\tthis.hooksForType = this._hookSystem.hooksForType.bind(this._hookSystem);\n\t\tthis.createScope = this._hookSystem.createScope.bind(this._hookSystem);\n\t}\n\n\tprivate async _loadPlugin(\n\t\tpluginRegistration: SliceMachineConfigPluginRegistration,\n\t): Promise<LoadedSliceMachinePlugin> {\n\t\t// Sanitize registration\n\t\tconst { resolve, options = {} } =\n\t\t\ttypeof pluginRegistration === \"object\" && \"resolve\" in pluginRegistration\n\t\t\t\t? pluginRegistration\n\t\t\t\t: { resolve: pluginRegistration };\n\n\t\tlet plugin: SliceMachinePlugin | undefined = undefined;\n\n\t\tif (typeof resolve === \"string\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\ttry {\n\t\t\t\tconst noop = path.resolve(this._project.root, \"noop.js\");\n\n\t\t\t\tlet resolvedID = resolve;\n\n\t\t\t\t// Support Yarn PnP\n\t\t\t\tif (\n\t\t\t\t\tprocess.versions.pnp &&\n\t\t\t\t\t\"findPnpApi\" in _module &&\n\t\t\t\t\ttypeof _module.findPnpApi === \"function\"\n\t\t\t\t) {\n\t\t\t\t\tconst pnpApi = _module.findPnpApi(noop);\n\t\t\t\t\tif (pnpApi) {\n\t\t\t\t\t\tresolvedID = pnpApi.resolveRequest(resolve, noop);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst raw = await createRequire(noop)(resolvedID);\n\t\t\t\tplugin = raw.default || raw;\n\t\t\t} catch (error) {\n\t\t\t\t// Only log in development, but not during tests when a native plugin matches.\n\t\t\t\tif (\n\t\t\t\t\timport.meta.env.DEV &&\n\t\t\t\t\t!(import.meta.env.TEST && resolve in this._nativePlugins)\n\t\t\t\t) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\t// If an installed plugin cannot be resolved, try loading a native plugin.\n\t\t\t\tplugin = this._nativePlugins[resolve];\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not resolve plugin \\`${resolve}\\`. Check that it has been installed.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tplugin = resolve;\n\t\t}\n\n\t\tif (!plugin) {\n\t\t\tthrow new Error(`Could not load plugin: \\`${resolve}\\``);\n\t\t}\n\n\t\tconst mergedOptions = defu(options, plugin.defaultOptions || {});\n\n\t\treturn {\n\t\t\t...plugin,\n\t\t\tresolve,\n\t\t\toptions: mergedOptions,\n\t\t};\n\t}\n\n\tprivate async _setupPlugin(\n\t\tplugin: LoadedSliceMachinePlugin,\n\t\tas: \"adapter\" | \"plugin\",\n\t): Promise<void> {\n\t\tconst context = createSliceMachineContext({\n\t\t\tactions: this.rawActions,\n\t\t\thelpers: this.rawHelpers,\n\t\t\tproject: this._project,\n\t\t\tplugin,\n\t\t});\n\t\tconst hookSystemScope =\n\t\t\tthis._hookSystem.createScope<SliceMachineHookExtraArgs>(\n\t\t\t\tplugin.meta.name,\n\t\t\t\t[context],\n\t\t\t);\n\n\t\t// Prevent plugins from hooking to adapter only hooks\n\t\tconst hook: typeof hookSystemScope.hook =\n\t\t\tas === \"adapter\"\n\t\t\t\t? hookSystemScope.hook\n\t\t\t\t: (type, hook, ...args) => {\n\t\t\t\t\t\tif (ADAPTER_ONLY_HOOKS.includes(type)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn hookSystemScope.hook(type, hook, ...args);\n\t\t\t\t };\n\n\t\t// Run plugin setup with actions and context\n\t\ttry {\n\t\t\tawait plugin.setup({\n\t\t\t\t...context,\n\t\t\t\thook,\n\t\t\t\tunhook: hookSystemScope.unhook,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error.message}`,\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _validateAdapter(adapter: LoadedSliceMachinePlugin): void {\n\t\tconst hooks = this._hookSystem.hooksForOwner(adapter.meta.name);\n\t\tconst hookTypes = hooks.map((hook) => hook.meta.type);\n\n\t\tconst missingHooks = REQUIRED_ADAPTER_HOOKS.filter(\n\t\t\t(requiredHookType) => !hookTypes.includes(requiredHookType),\n\t\t);\n\n\t\tif (missingHooks.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Adapter \\`${\n\t\t\t\t\tadapter.meta.name\n\t\t\t\t}\\` is missing hooks: \\`${missingHooks.join(\"`, `\")}\\``,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync init(): Promise<void> {\n\t\tconst [adapter, ...plugins] = await Promise.all(\n\t\t\t[\n\t\t\t\tthis._project.config.adapter,\n\t\t\t\t...(this._project.config.plugins ?? []),\n\t\t\t].map((pluginRegistration) => this._loadPlugin(pluginRegistration)),\n\t\t);\n\n\t\tawait Promise.all([\n\t\t\tthis._setupPlugin(adapter, \"adapter\"),\n\t\t\t...plugins.map((plugin) => this._setupPlugin(plugin, \"plugin\")),\n\t\t]);\n\n\t\tthis._validateAdapter(adapter);\n\t}\n}\n\ntype CreateSliceMachinePluginRunnerArgs = {\n\tproject: SliceMachineProject;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport const createSliceMachinePluginRunner = ({\n\tproject,\n\tnativePlugins,\n}: CreateSliceMachinePluginRunnerArgs): SliceMachinePluginRunner => {\n\tconst hookSystem = createSliceMachineHookSystem();\n\n\treturn new SliceMachinePluginRunner({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins,\n\t});\n};\n"],"names":["createSliceMachineActions","createSliceMachineHelpers","path","createRequire","defu","createSliceMachineContext","hook","createSliceMachineHookSystem"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BO,MAAM,yBAAkD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKM,MAAM,qBAA8C;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;MAYY,yBAAwB;AAAA,EA+BpC,YAAY,EACX,SACA,YACA,gBAAgB,CAAA,KACyB;AAlClC;AACA;AACA;AAUR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;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qB,CAAC,UAAU,SAAS,gBAAgB,CAAC;AAG5D,QAAI,aAAa,QAAQ;AACxB,YAAM,IAAI,MACT,aACC,QAAQ,KAAK,IACd,0BAA0B,aAAa,KAAK,MAAM,CAAC,IAAI;AAAA,IAEzD;AAAA,EACD;AAAA,EAEA,MAAM,OAAI;AACT,UAAM,CAAC,SAAS,GAAG,OAAO,IAAI,MAAM,QAAQ,IAC3C;AAAA,MACC,KAAK,SAAS,OAAO;AAAA,MACrB,GAAI,KAAK,SAAS,OAAO,WAAW,CAAA;AAAA,IAAA,EACnC,IAAI,CAAC,uBAAuB,KAAK,YAAY,kBAAkB,CAAC,CAAC;AAGpE,UAAM,QAAQ,IAAI;AAAA,MACjB,KAAK,aAAa,SAAS,SAAS;AAAA,MACpC,GAAG,QAAQ,IAAI,CAAC,WAAW,KAAK,aAAa,QAAQ,QAAQ,CAAC;AAAA,IAAA,CAC9D;AAED,SAAK,iBAAiB,OAAO;AAAA,EAC9B;AACA;AAUM,MAAM,iCAAiC,CAAC,EAC9C,SACA,oBACkE;AAClE,QAAM,aAAaC,6BAAAA,6BAAA;AAEnB,SAAO,IAAI,yBAAyB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AACF;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSliceMachinePluginRunner.js","sources":["../../src/createSliceMachinePluginRunner.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport _module, { createRequire } from \"node:module\";\n\nimport { defu } from \"defu\";\n\nimport { HookSystem } from \"./lib/HookSystem\";\nimport { createSliceMachineContext } from \"./createSliceMachineContext\";\nimport {\n\tLoadedSliceMachinePlugin,\n\tSliceMachinePlugin,\n} from \"./defineSliceMachinePlugin\";\nimport {\n\tSliceMachineConfigPluginRegistration,\n\tSliceMachineHookExtraArgs,\n\tSliceMachineHookTypes,\n\tSliceMachineHooks,\n\tSliceMachineProject,\n} from \"./types\";\nimport { createSliceMachineHookSystem } from \"./createSliceMachineHookSystem\";\nimport {\n\tcreateSliceMachineActions,\n\tSliceMachineActions,\n} from \"./createSliceMachineActions\";\nimport {\n\tcreateSliceMachineHelpers,\n\tSliceMachineHelpers,\n} from \"./createSliceMachineHelpers\";\n\n/**\n * @internal\n */\nexport const REQUIRED_ADAPTER_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:create\",\n\t\"slice:read\",\n\t\"slice:rename\",\n\t\"slice:delete\",\n\t\"slice:update\",\n\t\"slice:asset:update\",\n\t\"slice:asset:read\",\n\t\"slice:asset:delete\",\n\t\"slice-library:read\",\n\t\"slice-library:update\",\n\t\"custom-type:create\",\n\t\"custom-type:read\",\n\t\"custom-type:rename\",\n\t\"custom-type:delete\",\n\t\"custom-type:update\",\n\t\"custom-type:asset:update\",\n\t\"custom-type:asset:read\",\n\t\"custom-type:asset:delete\",\n\t\"custom-type-library:read\",\n];\n/**\n * @internal\n */\nexport const ADAPTER_ONLY_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:read\",\n\t\"slice:asset:read\",\n\t\"slice-library:read\",\n\t\"custom-type:read\",\n\t\"custom-type:asset:read\",\n\t\"custom-type-library:read\",\n\t\"project:environment:read\",\n];\n\ntype SliceMachinePluginRunnerConstructorArgs = {\n\tproject: SliceMachineProject;\n\thookSystem: HookSystem<SliceMachineHooks>;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport class SliceMachinePluginRunner {\n\tprivate _project: SliceMachineProject;\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\tprivate _nativePlugins: Record<string, SliceMachinePlugin>;\n\n\t/**\n\t * Slice Machine actions provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawActions`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawActions: SliceMachineActions;\n\n\t/**\n\t * Slice Machine helpers provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawHelpers`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawHelpers: SliceMachineHelpers;\n\n\t// Methods forwarded to the plugin runner's hook system.\n\tcallHook: HookSystem<SliceMachineHooks>[\"callHook\"];\n\thooksForOwner: HookSystem<SliceMachineHooks>[\"hooksForOwner\"];\n\thooksForType: HookSystem<SliceMachineHooks>[\"hooksForType\"];\n\tcreateScope: HookSystem<SliceMachineHooks>[\"createScope\"];\n\n\tconstructor({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins = {},\n\t}: SliceMachinePluginRunnerConstructorArgs) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t\tthis._nativePlugins = nativePlugins;\n\n\t\tthis.rawActions = createSliceMachineActions(\n\t\t\tthis._project,\n\t\t\tthis._hookSystem,\n\t\t);\n\t\tthis.rawHelpers = createSliceMachineHelpers(this._project);\n\n\t\tthis.callHook = this._hookSystem.callHook.bind(this._hookSystem);\n\t\tthis.hooksForOwner = this._hookSystem.hooksForOwner.bind(this._hookSystem);\n\t\tthis.hooksForType = this._hookSystem.hooksForType.bind(this._hookSystem);\n\t\tthis.createScope = this._hookSystem.createScope.bind(this._hookSystem);\n\t}\n\n\tprivate async _loadPlugin(\n\t\tpluginRegistration: SliceMachineConfigPluginRegistration,\n\t): Promise<LoadedSliceMachinePlugin> {\n\t\t// Sanitize registration\n\t\tconst { resolve, options = {} } =\n\t\t\ttypeof pluginRegistration === \"object\" && \"resolve\" in pluginRegistration\n\t\t\t\t? pluginRegistration\n\t\t\t\t: { resolve: pluginRegistration };\n\n\t\tlet plugin: SliceMachinePlugin | undefined = undefined;\n\n\t\tif (typeof resolve === \"string\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\ttry {\n\t\t\t\tconst noop = path.resolve(this._project.root, \"noop.js\");\n\n\t\t\t\tlet resolvedID = resolve;\n\n\t\t\t\t// Support Yarn PnP\n\t\t\t\tif (\n\t\t\t\t\tprocess.versions.pnp &&\n\t\t\t\t\t\"findPnpApi\" in _module &&\n\t\t\t\t\ttypeof _module.findPnpApi === \"function\"\n\t\t\t\t) {\n\t\t\t\t\tconst pnpApi = _module.findPnpApi(noop);\n\t\t\t\t\tif (pnpApi) {\n\t\t\t\t\t\tresolvedID = pnpApi.resolveRequest(resolve, noop);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst raw = await createRequire(noop)(resolvedID);\n\t\t\t\tplugin = raw.default || raw;\n\t\t\t} catch (error) {\n\t\t\t\t// Only log in development, but not during tests when a native plugin matches.\n\t\t\t\tif (\n\t\t\t\t\timport.meta.env.DEV &&\n\t\t\t\t\t!(import.meta.env.TEST && resolve in this._nativePlugins)\n\t\t\t\t) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\t// If an installed plugin cannot be resolved, try loading a native plugin.\n\t\t\t\tplugin = this._nativePlugins[resolve];\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not resolve plugin \\`${resolve}\\`. Check that it has been installed.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tplugin = resolve;\n\t\t}\n\n\t\tif (!plugin) {\n\t\t\tthrow new Error(`Could not load plugin: \\`${resolve}\\``);\n\t\t}\n\n\t\tconst mergedOptions = defu(options, plugin.defaultOptions || {});\n\n\t\treturn {\n\t\t\t...plugin,\n\t\t\tresolve,\n\t\t\toptions: mergedOptions,\n\t\t};\n\t}\n\n\tprivate async _setupPlugin(\n\t\tplugin: LoadedSliceMachinePlugin,\n\t\tas: \"adapter\" | \"plugin\",\n\t): Promise<void> {\n\t\tconst context = createSliceMachineContext({\n\t\t\tactions: this.rawActions,\n\t\t\thelpers: this.rawHelpers,\n\t\t\tproject: this._project,\n\t\t\tplugin,\n\t\t});\n\t\tconst hookSystemScope =\n\t\t\tthis._hookSystem.createScope<SliceMachineHookExtraArgs>(\n\t\t\t\tplugin.meta.name,\n\t\t\t\t[context],\n\t\t\t);\n\n\t\t// Prevent plugins from hooking to adapter only hooks\n\t\tconst hook: typeof hookSystemScope.hook =\n\t\t\tas === \"adapter\"\n\t\t\t\t? hookSystemScope.hook\n\t\t\t\t: (type, hook, ...args) => {\n\t\t\t\t\t\tif (ADAPTER_ONLY_HOOKS.includes(type)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn hookSystemScope.hook(type, hook, ...args);\n\t\t\t\t };\n\n\t\t// Run plugin setup with actions and context\n\t\ttry {\n\t\t\tawait plugin.setup({\n\t\t\t\t...context,\n\t\t\t\thook,\n\t\t\t\tunhook: hookSystemScope.unhook,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error.message}`,\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _validateAdapter(adapter: LoadedSliceMachinePlugin): void {\n\t\tconst hooks = this._hookSystem.hooksForOwner(adapter.meta.name);\n\t\tconst hookTypes = hooks.map((hook) => hook.meta.type);\n\n\t\tconst missingHooks = REQUIRED_ADAPTER_HOOKS.filter(\n\t\t\t(requiredHookType) => !hookTypes.includes(requiredHookType),\n\t\t);\n\n\t\tif (missingHooks.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Adapter \\`${\n\t\t\t\t\tadapter.meta.name\n\t\t\t\t}\\` is missing hooks: \\`${missingHooks.join(\"`, `\")}\\``,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync init(): Promise<void> {\n\t\tconst [adapter, ...plugins] = await Promise.all(\n\t\t\t[\n\t\t\t\tthis._project.config.adapter,\n\t\t\t\t...(this._project.config.plugins ?? []),\n\t\t\t].map((pluginRegistration) => this._loadPlugin(pluginRegistration)),\n\t\t);\n\n\t\tawait Promise.all([\n\t\t\tthis._setupPlugin(adapter, \"adapter\"),\n\t\t\t...plugins.map((plugin) => this._setupPlugin(plugin, \"plugin\")),\n\t\t]);\n\n\t\tthis._validateAdapter(adapter);\n\t}\n}\n\ntype CreateSliceMachinePluginRunnerArgs = {\n\tproject: SliceMachineProject;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport const createSliceMachinePluginRunner = ({\n\tproject,\n\tnativePlugins,\n}: CreateSliceMachinePluginRunnerArgs): SliceMachinePluginRunner => {\n\tconst hookSystem = createSliceMachineHookSystem();\n\n\treturn new SliceMachinePluginRunner({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins,\n\t});\n};\n"],"names":["hook"],"mappings":";;;;;;;;;;AA+BO,MAAM,yBAAkD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKM,MAAM,qBAA8C;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;MAYY,yBAAwB;AAAA,EA+BpC,YAAY,EACX,SACA,YACA,gBAAgB,CAAA,KACyB;AAlClC;AACA;AACA;AAUR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA;AAAA;AACA;AACA;AACA;AAOC,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,iBAAiB;AAEtB,SAAK,aAAa,0BACjB,KAAK,UACL,KAAK,WAAW;AAEj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AAO,IAAI,MAAM,QAAQ,IAC3C;AAAA,MACC,KAAK,SAAS,OAAO;AAAA,MACrB,GAAI,KAAK,SAAS,OAAO,WAAW,CAAA;AAAA,IAAA,EACnC,IAAI,CAAC,uBAAuB,KAAK,YAAY,kBAAkB,CAAC,CAAC;AAGpE,UAAM,QAAQ,IAAI;AAAA,MACjB,KAAK,aAAa,SAAS,SAAS;AAAA,MACpC,GAAG,QAAQ,IAAI,CAAC,WAAW,KAAK,aAAa,QAAQ,QAAQ,CAAC;AAAA,IAAA,CAC9D;AAED,SAAK,iBAAiB,OAAO;AAAA,EAC9B;AACA;AAUM,MAAM,iCAAiC,CAAC,EAC9C,SACA,oBACkE;AAClE,QAAM,aAAa,6BAAA;AAEnB,SAAO,IAAI,yBAAyB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AACF;"}
|
|
1
|
+
{"version":3,"file":"createSliceMachinePluginRunner.js","sources":["../../src/createSliceMachinePluginRunner.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport _module, { createRequire } from \"node:module\";\n\nimport { defu } from \"defu\";\n\nimport { HookSystem } from \"./lib/HookSystem\";\nimport { createSliceMachineContext } from \"./createSliceMachineContext\";\nimport {\n\tLoadedSliceMachinePlugin,\n\tSliceMachinePlugin,\n} from \"./defineSliceMachinePlugin\";\nimport {\n\tSliceMachineConfigPluginRegistration,\n\tSliceMachineHookExtraArgs,\n\tSliceMachineHookTypes,\n\tSliceMachineHooks,\n\tSliceMachineProject,\n} from \"./types\";\nimport { createSliceMachineHookSystem } from \"./createSliceMachineHookSystem\";\nimport {\n\tcreateSliceMachineActions,\n\tSliceMachineActions,\n} from \"./createSliceMachineActions\";\nimport {\n\tcreateSliceMachineHelpers,\n\tSliceMachineHelpers,\n} from \"./createSliceMachineHelpers\";\n\n/**\n * @internal\n */\nexport const REQUIRED_ADAPTER_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:create\",\n\t\"slice:read\",\n\t\"slice:rename\",\n\t\"slice:delete\",\n\t\"slice:update\",\n\t\"slice:asset:update\",\n\t\"slice:asset:read\",\n\t\"slice:asset:delete\",\n\t\"slice-library:read\",\n\t\"custom-type:create\",\n\t\"custom-type:read\",\n\t\"custom-type:rename\",\n\t\"custom-type:delete\",\n\t\"custom-type:update\",\n\t\"custom-type:asset:update\",\n\t\"custom-type:asset:read\",\n\t\"custom-type:asset:delete\",\n\t\"custom-type-library:read\",\n];\n/**\n * @internal\n */\nexport const ADAPTER_ONLY_HOOKS: SliceMachineHookTypes[] = [\n\t\"slice:read\",\n\t\"slice:asset:read\",\n\t\"slice-library:read\",\n\t\"custom-type:read\",\n\t\"custom-type:asset:read\",\n\t\"custom-type-library:read\",\n\t\"project:environment:read\",\n];\n\ntype SliceMachinePluginRunnerConstructorArgs = {\n\tproject: SliceMachineProject;\n\thookSystem: HookSystem<SliceMachineHooks>;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport class SliceMachinePluginRunner {\n\tprivate _project: SliceMachineProject;\n\tprivate _hookSystem: HookSystem<SliceMachineHooks>;\n\tprivate _nativePlugins: Record<string, SliceMachinePlugin>;\n\n\t/**\n\t * Slice Machine actions provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawActions`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawActions: SliceMachineActions;\n\n\t/**\n\t * Slice Machine helpers provided to hooks.\n\t *\n\t * IMPORTANT: Prefer creating your own abstraction over using `rawHelpers`\n\t * directly to prevent code breakage if this internal API changes.\n\t *\n\t * @internal\n\t */\n\trawHelpers: SliceMachineHelpers;\n\n\t// Methods forwarded to the plugin runner's hook system.\n\tcallHook: HookSystem<SliceMachineHooks>[\"callHook\"];\n\thooksForOwner: HookSystem<SliceMachineHooks>[\"hooksForOwner\"];\n\thooksForType: HookSystem<SliceMachineHooks>[\"hooksForType\"];\n\tcreateScope: HookSystem<SliceMachineHooks>[\"createScope\"];\n\n\tconstructor({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins = {},\n\t}: SliceMachinePluginRunnerConstructorArgs) {\n\t\tthis._project = project;\n\t\tthis._hookSystem = hookSystem;\n\t\tthis._nativePlugins = nativePlugins;\n\n\t\tthis.rawActions = createSliceMachineActions(\n\t\t\tthis._project,\n\t\t\tthis._hookSystem,\n\t\t);\n\t\tthis.rawHelpers = createSliceMachineHelpers(this._project);\n\n\t\tthis.callHook = this._hookSystem.callHook.bind(this._hookSystem);\n\t\tthis.hooksForOwner = this._hookSystem.hooksForOwner.bind(this._hookSystem);\n\t\tthis.hooksForType = this._hookSystem.hooksForType.bind(this._hookSystem);\n\t\tthis.createScope = this._hookSystem.createScope.bind(this._hookSystem);\n\t}\n\n\tprivate async _loadPlugin(\n\t\tpluginRegistration: SliceMachineConfigPluginRegistration,\n\t): Promise<LoadedSliceMachinePlugin> {\n\t\t// Sanitize registration\n\t\tconst { resolve, options = {} } =\n\t\t\ttypeof pluginRegistration === \"object\" && \"resolve\" in pluginRegistration\n\t\t\t\t? pluginRegistration\n\t\t\t\t: { resolve: pluginRegistration };\n\n\t\tlet plugin: SliceMachinePlugin | undefined = undefined;\n\n\t\tif (typeof resolve === \"string\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\ttry {\n\t\t\t\tconst noop = path.resolve(this._project.root, \"noop.js\");\n\n\t\t\t\tlet resolvedID = resolve;\n\n\t\t\t\t// Support Yarn PnP\n\t\t\t\tif (\n\t\t\t\t\tprocess.versions.pnp &&\n\t\t\t\t\t\"findPnpApi\" in _module &&\n\t\t\t\t\ttypeof _module.findPnpApi === \"function\"\n\t\t\t\t) {\n\t\t\t\t\tconst pnpApi = _module.findPnpApi(noop);\n\t\t\t\t\tif (pnpApi) {\n\t\t\t\t\t\tresolvedID = pnpApi.resolveRequest(resolve, noop);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst raw = await createRequire(noop)(resolvedID);\n\t\t\t\tplugin = raw.default || raw;\n\t\t\t} catch (error) {\n\t\t\t\t// Only log in development, but not during tests when a native plugin matches.\n\t\t\t\tif (\n\t\t\t\t\timport.meta.env.DEV &&\n\t\t\t\t\t!(import.meta.env.TEST && resolve in this._nativePlugins)\n\t\t\t\t) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\t// If an installed plugin cannot be resolved, try loading a native plugin.\n\t\t\t\tplugin = this._nativePlugins[resolve];\n\t\t\t}\n\n\t\t\tif (!plugin) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Could not resolve plugin \\`${resolve}\\`. Check that it has been installed.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tplugin = resolve;\n\t\t}\n\n\t\tif (!plugin) {\n\t\t\tthrow new Error(`Could not load plugin: \\`${resolve}\\``);\n\t\t}\n\n\t\tconst mergedOptions = defu(options, plugin.defaultOptions || {});\n\n\t\treturn {\n\t\t\t...plugin,\n\t\t\tresolve,\n\t\t\toptions: mergedOptions,\n\t\t};\n\t}\n\n\tprivate async _setupPlugin(\n\t\tplugin: LoadedSliceMachinePlugin,\n\t\tas: \"adapter\" | \"plugin\",\n\t): Promise<void> {\n\t\tconst context = createSliceMachineContext({\n\t\t\tactions: this.rawActions,\n\t\t\thelpers: this.rawHelpers,\n\t\t\tproject: this._project,\n\t\t\tplugin,\n\t\t});\n\t\tconst hookSystemScope =\n\t\t\tthis._hookSystem.createScope<SliceMachineHookExtraArgs>(\n\t\t\t\tplugin.meta.name,\n\t\t\t\t[context],\n\t\t\t);\n\n\t\t// Prevent plugins from hooking to adapter only hooks\n\t\tconst hook: typeof hookSystemScope.hook =\n\t\t\tas === \"adapter\"\n\t\t\t\t? hookSystemScope.hook\n\t\t\t\t: (type, hook, ...args) => {\n\t\t\t\t\t\tif (ADAPTER_ONLY_HOOKS.includes(type)) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn hookSystemScope.hook(type, hook, ...args);\n\t\t\t\t };\n\n\t\t// Run plugin setup with actions and context\n\t\ttry {\n\t\t\tawait plugin.setup({\n\t\t\t\t...context,\n\t\t\t\thook,\n\t\t\t\tunhook: hookSystemScope.unhook,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error.message}`,\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Plugin \\`${plugin.meta.name}\\` errored during setup: ${error}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _validateAdapter(adapter: LoadedSliceMachinePlugin): void {\n\t\tconst hooks = this._hookSystem.hooksForOwner(adapter.meta.name);\n\t\tconst hookTypes = hooks.map((hook) => hook.meta.type);\n\n\t\tconst missingHooks = REQUIRED_ADAPTER_HOOKS.filter(\n\t\t\t(requiredHookType) => !hookTypes.includes(requiredHookType),\n\t\t);\n\n\t\tif (missingHooks.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Adapter \\`${\n\t\t\t\t\tadapter.meta.name\n\t\t\t\t}\\` is missing hooks: \\`${missingHooks.join(\"`, `\")}\\``,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync init(): Promise<void> {\n\t\tconst [adapter, ...plugins] = await Promise.all(\n\t\t\t[\n\t\t\t\tthis._project.config.adapter,\n\t\t\t\t...(this._project.config.plugins ?? []),\n\t\t\t].map((pluginRegistration) => this._loadPlugin(pluginRegistration)),\n\t\t);\n\n\t\tawait Promise.all([\n\t\t\tthis._setupPlugin(adapter, \"adapter\"),\n\t\t\t...plugins.map((plugin) => this._setupPlugin(plugin, \"plugin\")),\n\t\t]);\n\n\t\tthis._validateAdapter(adapter);\n\t}\n}\n\ntype CreateSliceMachinePluginRunnerArgs = {\n\tproject: SliceMachineProject;\n\tnativePlugins?: Record<string, SliceMachinePlugin>;\n};\n\n/**\n * @internal\n */\nexport const createSliceMachinePluginRunner = ({\n\tproject,\n\tnativePlugins,\n}: CreateSliceMachinePluginRunnerArgs): SliceMachinePluginRunner => {\n\tconst hookSystem = createSliceMachineHookSystem();\n\n\treturn new SliceMachinePluginRunner({\n\t\tproject,\n\t\thookSystem,\n\t\tnativePlugins,\n\t});\n};\n"],"names":["hook"],"mappings":";;;;;;;;;;AA+BO,MAAM,yBAAkD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;AAKM,MAAM,qBAA8C;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;;MAYY,yBAAwB;AAAA,EA+BpC,YAAY,EACX,SACA,YACA,gBAAgB,CAAA,KACyB;AAlClC;AACA;AACA;AAUR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA;AAAA;AACA;AACA;AACA;AAOC,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,iBAAiB;AAEtB,SAAK,aAAa,0BACjB,KAAK,UACL,KAAK,WAAW;AAEjB,SAAK,aAAa,0BAA0B,KAAK,QAAQ;AAEzD,SAAK,WAAW,KAAK,YAAY,SAAS,KAAK,KAAK,WAAW;AAC/D,SAAK,gBAAgB,KAAK,YAAY,cAAc,KAAK,KAAK,WAAW;AACzE,SAAK,eAAe,KAAK,YAAY,aAAa,KAAK,KAAK,WAAW;AACvE,SAAK,cAAc,KAAK,YAAY,YAAY,KAAK,KAAK,WAAW;AAAA,EACtE;AAAA,EAEQ,MAAM,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K,aAAa,QAAQ,QAAQ,CAAC;AAAA,IAAA,CAC9D;AAED,SAAK,iBAAiB,OAAO;AAAA,EAC9B;AACA;AAUM,MAAM,iCAAiC,CAAC,EAC9C,SACA,oBACkE;AAClE,QAAM,aAAa,6BAAA;AAEnB,SAAO,IAAI,yBAAyB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AACF;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export type { SliceRenameHook, SliceRenameHookData, SliceRenameHookReturnType, }
|
|
|
16
16
|
export type { SliceDeleteHook, SliceDeleteHookData, SliceDeleteHookReturnType, } from "./hooks/slice-delete";
|
|
17
17
|
export type { SliceReadHook, SliceReadHookData, SliceReadHookReturnType, } from "./hooks/slice-read";
|
|
18
18
|
export type { SliceLibraryReadHook, SliceLibraryReadHookData, SliceLibraryReadHookReturnType, } from "./hooks/sliceLibrary-read";
|
|
19
|
-
export type { SliceLibraryUpdateHook, SliceLibraryUpdateHookData, SliceLibraryUpdateHookReturnType, } from "./hooks/sliceLibrary-update";
|
|
20
19
|
export type { CustomTypeAssetUpdateHook, CustomTypeAssetUpdateHookData, CustomTypeAssetUpdateHookReturnType, } from "./hooks/customType-asset-update";
|
|
21
20
|
export type { CustomTypeAssetDeleteHook, CustomTypeAssetDeleteHookData, CustomTypeAssetDeleteHookReturnType, } from "./hooks/customType-asset-delete";
|
|
22
21
|
export type { CustomTypeAssetReadHook, CustomTypeAssetReadHookData, CustomTypeAssetReadHookReturnType, } from "./hooks/customType-asset-read";
|
package/dist/types.cjs
CHANGED
|
@@ -10,7 +10,6 @@ const SliceMachineHookType = {
|
|
|
10
10
|
slice_asset_delete: "slice:asset:delete",
|
|
11
11
|
slice_asset_read: "slice:asset:read",
|
|
12
12
|
sliceLibrary_read: "slice-library:read",
|
|
13
|
-
sliceLibrary_update: "slice-library:update",
|
|
14
13
|
customType_create: "custom-type:create",
|
|
15
14
|
customType_update: "custom-type:update",
|
|
16
15
|
customType_rename: "custom-type:rename",
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../../src/types.ts"],"sourcesContent":["import { SliceMachineContext } from \"./createSliceMachineContext\";\nimport { SliceMachinePlugin } from \"./defineSliceMachinePlugin\";\nimport { Hook } from \"./lib/HookSystem\";\n\nimport { ProjectInitHookBase } from \"./hooks/project-init\";\nimport { CustomTypeAssetDeleteHookBase } from \"./hooks/customType-asset-delete\";\nimport { CustomTypeAssetReadHookBase } from \"./hooks/customType-asset-read\";\nimport { CustomTypeAssetUpdateHookBase } from \"./hooks/customType-asset-update\";\nimport { CustomTypeCreateHookBase } from \"./hooks/customType-create\";\nimport { CustomTypeDeleteHookBase } from \"./hooks/customType-delete\";\nimport { CustomTypeLibraryReadHookBase } from \"./hooks/customTypeLibrary-read\";\nimport { CustomTypeReadHookBase } from \"./hooks/customType-read\";\nimport { CustomTypeRenameHookBase } from \"./hooks/customType-rename\";\nimport { CustomTypeUpdateHookBase } from \"./hooks/customType-update\";\nimport { DebugHookBase } from \"./hooks/debug\";\nimport { SliceAssetDeleteHookBase } from \"./hooks/slice-asset-delete\";\nimport { SliceAssetReadHookBase } from \"./hooks/slice-asset-read\";\nimport { SliceAssetUpdateHookBase } from \"./hooks/slice-asset-update\";\nimport { SliceCreateHookBase } from \"./hooks/slice-create\";\nimport { SliceDeleteHookBase } from \"./hooks/slice-delete\";\nimport { SliceLibraryReadHookBase } from \"./hooks/sliceLibrary-read\";\nimport {
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../../src/types.ts"],"sourcesContent":["import { SliceMachineContext } from \"./createSliceMachineContext\";\nimport { SliceMachinePlugin } from \"./defineSliceMachinePlugin\";\nimport { Hook } from \"./lib/HookSystem\";\n\nimport { ProjectInitHookBase } from \"./hooks/project-init\";\nimport { CustomTypeAssetDeleteHookBase } from \"./hooks/customType-asset-delete\";\nimport { CustomTypeAssetReadHookBase } from \"./hooks/customType-asset-read\";\nimport { CustomTypeAssetUpdateHookBase } from \"./hooks/customType-asset-update\";\nimport { CustomTypeCreateHookBase } from \"./hooks/customType-create\";\nimport { CustomTypeDeleteHookBase } from \"./hooks/customType-delete\";\nimport { CustomTypeLibraryReadHookBase } from \"./hooks/customTypeLibrary-read\";\nimport { CustomTypeReadHookBase } from \"./hooks/customType-read\";\nimport { CustomTypeRenameHookBase } from \"./hooks/customType-rename\";\nimport { CustomTypeUpdateHookBase } from \"./hooks/customType-update\";\nimport { DebugHookBase } from \"./hooks/debug\";\nimport { SliceAssetDeleteHookBase } from \"./hooks/slice-asset-delete\";\nimport { SliceAssetReadHookBase } from \"./hooks/slice-asset-read\";\nimport { SliceAssetUpdateHookBase } from \"./hooks/slice-asset-update\";\nimport { SliceCreateHookBase } from \"./hooks/slice-create\";\nimport { SliceDeleteHookBase } from \"./hooks/slice-delete\";\nimport { SliceLibraryReadHookBase } from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookBase } from \"./hooks/slice-read\";\nimport { SliceRenameHookBase } from \"./hooks/slice-rename\";\nimport { SliceUpdateHookBase } from \"./hooks/slice-update\";\nimport { SnippetReadHookBase } from \"./hooks/snippet-read\";\nimport { DocumentationReadHookBase } from \"./hooks/documentation-read\";\n\nimport { SliceTemplateLibraryReadHookBase } from \"./hooks/sliceTemplateLibrary-read\";\nimport { ProjectEnvironmentReadHookBase } from \"./hooks/project-environment-read\";\nimport { ProjectEnvironmentUpdateHookBase } from \"./hooks/project-environment-update\";\n\n/**\n * A value optionally wrapped in a `PromiseLike`.\n *\n * @typeParam T - The value that can optionally be wrapped.\n */\nexport type Promisable<T> = T | PromiseLike<T>;\n\n/**\n * A generic type for a user-provided plugin options. Prefer using a\n * plugin-specific type over this type.\n */\nexport type SliceMachinePluginOptions = Record<string, unknown>;\n\n/**\n * A string, object, or instance representing a registered plugin.\n *\n * @typeParam TPluginOptions - User-provided options for the plugin.\n */\nexport type SliceMachineConfigPluginRegistration<\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> =\n\t| string\n\t| SliceMachinePlugin\n\t| {\n\t\t\tresolve: string | SliceMachinePlugin;\n\t\t\toptions?: TPluginOptions;\n\t };\n\n/**\n * Slice Machine configuration from `slicemachine.config.js`.\n */\nexport type SliceMachineConfig = {\n\t// TODO: Can we make `apiEndpoint` optional?\n\tapiEndpoint?: string;\n\t// NOTE: This is a new property.\n\trepositoryName: string;\n\tlocalSliceSimulatorURL?: string;\n\tlibraries?: string[];\n\tadapter: SliceMachineConfigPluginRegistration;\n\tplugins?: SliceMachineConfigPluginRegistration[];\n\tlabs?: { legacySliceUpgrader?: boolean };\n};\n\n/**\n * Slice Machine project metadata.\n */\nexport type SliceMachineProject = {\n\t/**\n\t * An absolute path to project root.\n\t */\n\troot: string;\n\t/**\n\t * Slice Machine `slicemachine.config.json` content, validated.\n\t */\n\tconfig: SliceMachineConfig;\n};\n\n/**\n * A Slice Library's metadata.\n */\nexport type SliceLibrary = {\n\tid: string;\n};\n\n// ============================================================================\n//\n// # HOOK TYPES\n//\n// ============================================================================\n\n/**\n * A hook handler.\n */\nexport type SliceMachineHook<TData, TReturn> = (\n\tdata: TData,\n) => Promisable<TReturn>;\n\n/**\n * Extra arguments provided to hooks when called.\n *\n * @typeParam TPluginOptions - User-provided options for the hook's plugin.\n */\nexport type SliceMachineHookExtraArgs<\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> = [context: SliceMachineContext<TPluginOptions>];\n\n/**\n * Utility type to extend a hook handler's type with Slice Machine-specific\n * extra arguments.\n *\n * @typeParam THook - Hook handler to extend.\n * @typeParam TPluginOptions - User-provided options for the hook's plugin.\n */\nexport type ExtendSliceMachineHook<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTHook extends SliceMachineHook<any, any>,\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> = (\n\t...args: [\n\t\t...args: Parameters<THook>,\n\t\t...extraArgs: SliceMachineHookExtraArgs<TPluginOptions>,\n\t]\n) => ReturnType<THook>;\n\n/**\n * Hook types.\n */\nexport const SliceMachineHookType = {\n\tslice_create: \"slice:create\",\n\tslice_update: \"slice:update\",\n\tslice_rename: \"slice:rename\",\n\tslice_delete: \"slice:delete\",\n\tslice_read: \"slice:read\",\n\tslice_asset_update: \"slice:asset:update\",\n\tslice_asset_delete: \"slice:asset:delete\",\n\tslice_asset_read: \"slice:asset:read\",\n\tsliceLibrary_read: \"slice-library:read\",\n\n\tcustomType_create: \"custom-type:create\",\n\tcustomType_update: \"custom-type:update\",\n\tcustomType_rename: \"custom-type:rename\",\n\tcustomType_delete: \"custom-type:delete\",\n\tcustomType_read: \"custom-type:read\",\n\tcustomType_asset_update: \"custom-type:asset:update\",\n\tcustomType_asset_delete: \"custom-type:asset:delete\",\n\tcustomType_asset_read: \"custom-type:asset:read\",\n\tcustomTypeLibrary_read: \"custom-type-library:read\",\n\tdocumentation_read: \"documentation:read\",\n\tsliceTemplateLibrary_read: \"slice-template-library:read\",\n\n\tsnippet_read: \"snippet:read\",\n\n\tproject_init: \"project:init\",\n\tproject_environment_read: \"project:environment:read\",\n\tproject_environment_update: \"project:environment:update\",\n\n\tdebug: \"debug\",\n} as const;\n\n/**\n * Hook types.\n */\nexport type SliceMachineHookTypes =\n\t(typeof SliceMachineHookType)[keyof typeof SliceMachineHookType];\n\n/**\n * Slice Machine-specific hook handlers.\n */\nexport type SliceMachineHooks = {\n\t// Slices\n\t[SliceMachineHookType.slice_create]: Hook<SliceCreateHookBase>;\n\t[SliceMachineHookType.slice_update]: Hook<SliceUpdateHookBase>;\n\t[SliceMachineHookType.slice_rename]: Hook<SliceRenameHookBase>;\n\t[SliceMachineHookType.slice_delete]: Hook<SliceDeleteHookBase>;\n\t[SliceMachineHookType.slice_read]: Hook<SliceReadHookBase>;\n\t[SliceMachineHookType.slice_asset_update]: Hook<SliceAssetUpdateHookBase>;\n\t[SliceMachineHookType.slice_asset_delete]: Hook<SliceAssetDeleteHookBase>;\n\t[SliceMachineHookType.slice_asset_read]: Hook<SliceAssetReadHookBase>;\n\n\t// Slice Libraries\n\t[SliceMachineHookType.sliceLibrary_read]: Hook<SliceLibraryReadHookBase>;\n\n\t// Custom Types\n\t[SliceMachineHookType.customType_create]: Hook<CustomTypeCreateHookBase>;\n\t[SliceMachineHookType.customType_update]: Hook<CustomTypeUpdateHookBase>;\n\t[SliceMachineHookType.customType_rename]: Hook<CustomTypeRenameHookBase>;\n\t[SliceMachineHookType.customType_delete]: Hook<CustomTypeDeleteHookBase>;\n\t[SliceMachineHookType.customType_read]: Hook<CustomTypeReadHookBase>;\n\t[SliceMachineHookType.customType_asset_update]: Hook<CustomTypeAssetUpdateHookBase>;\n\t[SliceMachineHookType.customType_asset_delete]: Hook<CustomTypeAssetDeleteHookBase>;\n\t[SliceMachineHookType.customType_asset_read]: Hook<CustomTypeAssetReadHookBase>;\n\n\t// Custom Type Libraries\n\t[SliceMachineHookType.customTypeLibrary_read]: Hook<CustomTypeLibraryReadHookBase>;\n\n\t// Snippets\n\t[SliceMachineHookType.snippet_read]: Hook<SnippetReadHookBase>;\n\n\t// Documentation\n\t[SliceMachineHookType.documentation_read]: Hook<DocumentationReadHookBase>;\n\n\t// Project\n\t[SliceMachineHookType.project_init]: Hook<ProjectInitHookBase>;\n\t[SliceMachineHookType.project_environment_read]: Hook<ProjectEnvironmentReadHookBase>;\n\t[SliceMachineHookType.project_environment_update]: Hook<ProjectEnvironmentUpdateHookBase>;\n\n\t// Debug\n\t[SliceMachineHookType.debug]: Hook<DebugHookBase>;\n\n\t// Slice templates\n\t[SliceMachineHookType.sliceTemplateLibrary_read]: Hook<SliceTemplateLibraryReadHookBase>;\n};\n"],"names":[],"mappings":";;AA0IO,MAAM,uBAAuB;AAAA,EACnC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EAEnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,yBAAyB;AAAA,EACzB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,2BAA2B;AAAA,EAE3B,cAAc;AAAA,EAEd,cAAc;AAAA,EACd,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,OAAO;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { SliceAssetUpdateHookBase } from "./hooks/slice-asset-update";
|
|
|
18
18
|
import { SliceCreateHookBase } from "./hooks/slice-create";
|
|
19
19
|
import { SliceDeleteHookBase } from "./hooks/slice-delete";
|
|
20
20
|
import { SliceLibraryReadHookBase } from "./hooks/sliceLibrary-read";
|
|
21
|
-
import { SliceLibraryUpdateHookBase } from "./hooks/sliceLibrary-update";
|
|
22
21
|
import { SliceReadHookBase } from "./hooks/slice-read";
|
|
23
22
|
import { SliceRenameHookBase } from "./hooks/slice-rename";
|
|
24
23
|
import { SliceUpdateHookBase } from "./hooks/slice-update";
|
|
@@ -114,7 +113,6 @@ export declare const SliceMachineHookType: {
|
|
|
114
113
|
readonly slice_asset_delete: "slice:asset:delete";
|
|
115
114
|
readonly slice_asset_read: "slice:asset:read";
|
|
116
115
|
readonly sliceLibrary_read: "slice-library:read";
|
|
117
|
-
readonly sliceLibrary_update: "slice-library:update";
|
|
118
116
|
readonly customType_create: "custom-type:create";
|
|
119
117
|
readonly customType_update: "custom-type:update";
|
|
120
118
|
readonly customType_rename: "custom-type:rename";
|
|
@@ -149,7 +147,6 @@ export type SliceMachineHooks = {
|
|
|
149
147
|
[SliceMachineHookType.slice_asset_delete]: Hook<SliceAssetDeleteHookBase>;
|
|
150
148
|
[SliceMachineHookType.slice_asset_read]: Hook<SliceAssetReadHookBase>;
|
|
151
149
|
[SliceMachineHookType.sliceLibrary_read]: Hook<SliceLibraryReadHookBase>;
|
|
152
|
-
[SliceMachineHookType.sliceLibrary_update]: Hook<SliceLibraryUpdateHookBase>;
|
|
153
150
|
[SliceMachineHookType.customType_create]: Hook<CustomTypeCreateHookBase>;
|
|
154
151
|
[SliceMachineHookType.customType_update]: Hook<CustomTypeUpdateHookBase>;
|
|
155
152
|
[SliceMachineHookType.customType_rename]: Hook<CustomTypeRenameHookBase>;
|
package/dist/types.js
CHANGED
|
@@ -8,7 +8,6 @@ const SliceMachineHookType = {
|
|
|
8
8
|
slice_asset_delete: "slice:asset:delete",
|
|
9
9
|
slice_asset_read: "slice:asset:read",
|
|
10
10
|
sliceLibrary_read: "slice-library:read",
|
|
11
|
-
sliceLibrary_update: "slice-library:update",
|
|
12
11
|
customType_create: "custom-type:create",
|
|
13
12
|
customType_update: "custom-type:update",
|
|
14
13
|
customType_rename: "custom-type:rename",
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../src/types.ts"],"sourcesContent":["import { SliceMachineContext } from \"./createSliceMachineContext\";\nimport { SliceMachinePlugin } from \"./defineSliceMachinePlugin\";\nimport { Hook } from \"./lib/HookSystem\";\n\nimport { ProjectInitHookBase } from \"./hooks/project-init\";\nimport { CustomTypeAssetDeleteHookBase } from \"./hooks/customType-asset-delete\";\nimport { CustomTypeAssetReadHookBase } from \"./hooks/customType-asset-read\";\nimport { CustomTypeAssetUpdateHookBase } from \"./hooks/customType-asset-update\";\nimport { CustomTypeCreateHookBase } from \"./hooks/customType-create\";\nimport { CustomTypeDeleteHookBase } from \"./hooks/customType-delete\";\nimport { CustomTypeLibraryReadHookBase } from \"./hooks/customTypeLibrary-read\";\nimport { CustomTypeReadHookBase } from \"./hooks/customType-read\";\nimport { CustomTypeRenameHookBase } from \"./hooks/customType-rename\";\nimport { CustomTypeUpdateHookBase } from \"./hooks/customType-update\";\nimport { DebugHookBase } from \"./hooks/debug\";\nimport { SliceAssetDeleteHookBase } from \"./hooks/slice-asset-delete\";\nimport { SliceAssetReadHookBase } from \"./hooks/slice-asset-read\";\nimport { SliceAssetUpdateHookBase } from \"./hooks/slice-asset-update\";\nimport { SliceCreateHookBase } from \"./hooks/slice-create\";\nimport { SliceDeleteHookBase } from \"./hooks/slice-delete\";\nimport { SliceLibraryReadHookBase } from \"./hooks/sliceLibrary-read\";\nimport {
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/types.ts"],"sourcesContent":["import { SliceMachineContext } from \"./createSliceMachineContext\";\nimport { SliceMachinePlugin } from \"./defineSliceMachinePlugin\";\nimport { Hook } from \"./lib/HookSystem\";\n\nimport { ProjectInitHookBase } from \"./hooks/project-init\";\nimport { CustomTypeAssetDeleteHookBase } from \"./hooks/customType-asset-delete\";\nimport { CustomTypeAssetReadHookBase } from \"./hooks/customType-asset-read\";\nimport { CustomTypeAssetUpdateHookBase } from \"./hooks/customType-asset-update\";\nimport { CustomTypeCreateHookBase } from \"./hooks/customType-create\";\nimport { CustomTypeDeleteHookBase } from \"./hooks/customType-delete\";\nimport { CustomTypeLibraryReadHookBase } from \"./hooks/customTypeLibrary-read\";\nimport { CustomTypeReadHookBase } from \"./hooks/customType-read\";\nimport { CustomTypeRenameHookBase } from \"./hooks/customType-rename\";\nimport { CustomTypeUpdateHookBase } from \"./hooks/customType-update\";\nimport { DebugHookBase } from \"./hooks/debug\";\nimport { SliceAssetDeleteHookBase } from \"./hooks/slice-asset-delete\";\nimport { SliceAssetReadHookBase } from \"./hooks/slice-asset-read\";\nimport { SliceAssetUpdateHookBase } from \"./hooks/slice-asset-update\";\nimport { SliceCreateHookBase } from \"./hooks/slice-create\";\nimport { SliceDeleteHookBase } from \"./hooks/slice-delete\";\nimport { SliceLibraryReadHookBase } from \"./hooks/sliceLibrary-read\";\nimport { SliceReadHookBase } from \"./hooks/slice-read\";\nimport { SliceRenameHookBase } from \"./hooks/slice-rename\";\nimport { SliceUpdateHookBase } from \"./hooks/slice-update\";\nimport { SnippetReadHookBase } from \"./hooks/snippet-read\";\nimport { DocumentationReadHookBase } from \"./hooks/documentation-read\";\n\nimport { SliceTemplateLibraryReadHookBase } from \"./hooks/sliceTemplateLibrary-read\";\nimport { ProjectEnvironmentReadHookBase } from \"./hooks/project-environment-read\";\nimport { ProjectEnvironmentUpdateHookBase } from \"./hooks/project-environment-update\";\n\n/**\n * A value optionally wrapped in a `PromiseLike`.\n *\n * @typeParam T - The value that can optionally be wrapped.\n */\nexport type Promisable<T> = T | PromiseLike<T>;\n\n/**\n * A generic type for a user-provided plugin options. Prefer using a\n * plugin-specific type over this type.\n */\nexport type SliceMachinePluginOptions = Record<string, unknown>;\n\n/**\n * A string, object, or instance representing a registered plugin.\n *\n * @typeParam TPluginOptions - User-provided options for the plugin.\n */\nexport type SliceMachineConfigPluginRegistration<\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> =\n\t| string\n\t| SliceMachinePlugin\n\t| {\n\t\t\tresolve: string | SliceMachinePlugin;\n\t\t\toptions?: TPluginOptions;\n\t };\n\n/**\n * Slice Machine configuration from `slicemachine.config.js`.\n */\nexport type SliceMachineConfig = {\n\t// TODO: Can we make `apiEndpoint` optional?\n\tapiEndpoint?: string;\n\t// NOTE: This is a new property.\n\trepositoryName: string;\n\tlocalSliceSimulatorURL?: string;\n\tlibraries?: string[];\n\tadapter: SliceMachineConfigPluginRegistration;\n\tplugins?: SliceMachineConfigPluginRegistration[];\n\tlabs?: { legacySliceUpgrader?: boolean };\n};\n\n/**\n * Slice Machine project metadata.\n */\nexport type SliceMachineProject = {\n\t/**\n\t * An absolute path to project root.\n\t */\n\troot: string;\n\t/**\n\t * Slice Machine `slicemachine.config.json` content, validated.\n\t */\n\tconfig: SliceMachineConfig;\n};\n\n/**\n * A Slice Library's metadata.\n */\nexport type SliceLibrary = {\n\tid: string;\n};\n\n// ============================================================================\n//\n// # HOOK TYPES\n//\n// ============================================================================\n\n/**\n * A hook handler.\n */\nexport type SliceMachineHook<TData, TReturn> = (\n\tdata: TData,\n) => Promisable<TReturn>;\n\n/**\n * Extra arguments provided to hooks when called.\n *\n * @typeParam TPluginOptions - User-provided options for the hook's plugin.\n */\nexport type SliceMachineHookExtraArgs<\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> = [context: SliceMachineContext<TPluginOptions>];\n\n/**\n * Utility type to extend a hook handler's type with Slice Machine-specific\n * extra arguments.\n *\n * @typeParam THook - Hook handler to extend.\n * @typeParam TPluginOptions - User-provided options for the hook's plugin.\n */\nexport type ExtendSliceMachineHook<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTHook extends SliceMachineHook<any, any>,\n\tTPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,\n> = (\n\t...args: [\n\t\t...args: Parameters<THook>,\n\t\t...extraArgs: SliceMachineHookExtraArgs<TPluginOptions>,\n\t]\n) => ReturnType<THook>;\n\n/**\n * Hook types.\n */\nexport const SliceMachineHookType = {\n\tslice_create: \"slice:create\",\n\tslice_update: \"slice:update\",\n\tslice_rename: \"slice:rename\",\n\tslice_delete: \"slice:delete\",\n\tslice_read: \"slice:read\",\n\tslice_asset_update: \"slice:asset:update\",\n\tslice_asset_delete: \"slice:asset:delete\",\n\tslice_asset_read: \"slice:asset:read\",\n\tsliceLibrary_read: \"slice-library:read\",\n\n\tcustomType_create: \"custom-type:create\",\n\tcustomType_update: \"custom-type:update\",\n\tcustomType_rename: \"custom-type:rename\",\n\tcustomType_delete: \"custom-type:delete\",\n\tcustomType_read: \"custom-type:read\",\n\tcustomType_asset_update: \"custom-type:asset:update\",\n\tcustomType_asset_delete: \"custom-type:asset:delete\",\n\tcustomType_asset_read: \"custom-type:asset:read\",\n\tcustomTypeLibrary_read: \"custom-type-library:read\",\n\tdocumentation_read: \"documentation:read\",\n\tsliceTemplateLibrary_read: \"slice-template-library:read\",\n\n\tsnippet_read: \"snippet:read\",\n\n\tproject_init: \"project:init\",\n\tproject_environment_read: \"project:environment:read\",\n\tproject_environment_update: \"project:environment:update\",\n\n\tdebug: \"debug\",\n} as const;\n\n/**\n * Hook types.\n */\nexport type SliceMachineHookTypes =\n\t(typeof SliceMachineHookType)[keyof typeof SliceMachineHookType];\n\n/**\n * Slice Machine-specific hook handlers.\n */\nexport type SliceMachineHooks = {\n\t// Slices\n\t[SliceMachineHookType.slice_create]: Hook<SliceCreateHookBase>;\n\t[SliceMachineHookType.slice_update]: Hook<SliceUpdateHookBase>;\n\t[SliceMachineHookType.slice_rename]: Hook<SliceRenameHookBase>;\n\t[SliceMachineHookType.slice_delete]: Hook<SliceDeleteHookBase>;\n\t[SliceMachineHookType.slice_read]: Hook<SliceReadHookBase>;\n\t[SliceMachineHookType.slice_asset_update]: Hook<SliceAssetUpdateHookBase>;\n\t[SliceMachineHookType.slice_asset_delete]: Hook<SliceAssetDeleteHookBase>;\n\t[SliceMachineHookType.slice_asset_read]: Hook<SliceAssetReadHookBase>;\n\n\t// Slice Libraries\n\t[SliceMachineHookType.sliceLibrary_read]: Hook<SliceLibraryReadHookBase>;\n\n\t// Custom Types\n\t[SliceMachineHookType.customType_create]: Hook<CustomTypeCreateHookBase>;\n\t[SliceMachineHookType.customType_update]: Hook<CustomTypeUpdateHookBase>;\n\t[SliceMachineHookType.customType_rename]: Hook<CustomTypeRenameHookBase>;\n\t[SliceMachineHookType.customType_delete]: Hook<CustomTypeDeleteHookBase>;\n\t[SliceMachineHookType.customType_read]: Hook<CustomTypeReadHookBase>;\n\t[SliceMachineHookType.customType_asset_update]: Hook<CustomTypeAssetUpdateHookBase>;\n\t[SliceMachineHookType.customType_asset_delete]: Hook<CustomTypeAssetDeleteHookBase>;\n\t[SliceMachineHookType.customType_asset_read]: Hook<CustomTypeAssetReadHookBase>;\n\n\t// Custom Type Libraries\n\t[SliceMachineHookType.customTypeLibrary_read]: Hook<CustomTypeLibraryReadHookBase>;\n\n\t// Snippets\n\t[SliceMachineHookType.snippet_read]: Hook<SnippetReadHookBase>;\n\n\t// Documentation\n\t[SliceMachineHookType.documentation_read]: Hook<DocumentationReadHookBase>;\n\n\t// Project\n\t[SliceMachineHookType.project_init]: Hook<ProjectInitHookBase>;\n\t[SliceMachineHookType.project_environment_read]: Hook<ProjectEnvironmentReadHookBase>;\n\t[SliceMachineHookType.project_environment_update]: Hook<ProjectEnvironmentUpdateHookBase>;\n\n\t// Debug\n\t[SliceMachineHookType.debug]: Hook<DebugHookBase>;\n\n\t// Slice templates\n\t[SliceMachineHookType.sliceTemplateLibrary_read]: Hook<SliceTemplateLibraryReadHookBase>;\n};\n"],"names":[],"mappings":"AA0IO,MAAM,uBAAuB;AAAA,EACnC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EAEnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,yBAAyB;AAAA,EACzB,yBAAyB;AAAA,EACzB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,2BAA2B;AAAA,EAE3B,cAAc;AAAA,EAEd,cAAc;AAAA,EACd,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,OAAO;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/plugin-kit",
|
|
3
|
-
"version": "0.4.83-alpha.jp-allow-slice-index-generation.
|
|
3
|
+
"version": "0.4.83-alpha.jp-allow-slice-index-generation.5",
|
|
4
4
|
"description": "A set of helpers to develop and run Slice Machine plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -11,10 +11,6 @@ import {
|
|
|
11
11
|
SliceLibraryReadHookReturnType,
|
|
12
12
|
} from "./hooks/sliceLibrary-read";
|
|
13
13
|
import { SliceReadHookData, SliceReadHookReturnType } from "./hooks/slice-read";
|
|
14
|
-
import {
|
|
15
|
-
SliceLibraryUpdateHookData,
|
|
16
|
-
SliceLibraryUpdateHookReturnType,
|
|
17
|
-
} from "./hooks/sliceLibrary-update";
|
|
18
14
|
|
|
19
15
|
export type ReadAllSliceModelsActionArgs<
|
|
20
16
|
TWithMetadata extends boolean = false,
|
|
@@ -146,14 +142,6 @@ export class SliceMachineActions {
|
|
|
146
142
|
return library;
|
|
147
143
|
};
|
|
148
144
|
|
|
149
|
-
updateSliceLibrary = async (
|
|
150
|
-
args: SliceLibraryUpdateHookData,
|
|
151
|
-
): Promise<SliceLibraryUpdateHookReturnType> => {
|
|
152
|
-
await this._hookSystem.callHook("slice-library:update", {
|
|
153
|
-
libraryID: args.libraryID,
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
|
|
157
145
|
readAllCustomTypeModels = async (): Promise<
|
|
158
146
|
CustomTypeReadHookReturnType[]
|
|
159
147
|
> => {
|
package/src/index.ts
CHANGED
|
@@ -98,13 +98,6 @@ export type {
|
|
|
98
98
|
SliceLibraryReadHookReturnType,
|
|
99
99
|
} from "./hooks/sliceLibrary-read";
|
|
100
100
|
|
|
101
|
-
// slice-library:update
|
|
102
|
-
export type {
|
|
103
|
-
SliceLibraryUpdateHook,
|
|
104
|
-
SliceLibraryUpdateHookData,
|
|
105
|
-
SliceLibraryUpdateHookReturnType,
|
|
106
|
-
} from "./hooks/sliceLibrary-update";
|
|
107
|
-
|
|
108
101
|
// custom-type:asset:update
|
|
109
102
|
export type {
|
|
110
103
|
CustomTypeAssetUpdateHook,
|
package/src/types.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { SliceAssetUpdateHookBase } from "./hooks/slice-asset-update";
|
|
|
19
19
|
import { SliceCreateHookBase } from "./hooks/slice-create";
|
|
20
20
|
import { SliceDeleteHookBase } from "./hooks/slice-delete";
|
|
21
21
|
import { SliceLibraryReadHookBase } from "./hooks/sliceLibrary-read";
|
|
22
|
-
import { SliceLibraryUpdateHookBase } from "./hooks/sliceLibrary-update";
|
|
23
22
|
import { SliceReadHookBase } from "./hooks/slice-read";
|
|
24
23
|
import { SliceRenameHookBase } from "./hooks/slice-rename";
|
|
25
24
|
import { SliceUpdateHookBase } from "./hooks/slice-update";
|
|
@@ -147,7 +146,6 @@ export const SliceMachineHookType = {
|
|
|
147
146
|
slice_asset_delete: "slice:asset:delete",
|
|
148
147
|
slice_asset_read: "slice:asset:read",
|
|
149
148
|
sliceLibrary_read: "slice-library:read",
|
|
150
|
-
sliceLibrary_update: "slice-library:update",
|
|
151
149
|
|
|
152
150
|
customType_create: "custom-type:create",
|
|
153
151
|
customType_update: "custom-type:update",
|
|
@@ -192,7 +190,6 @@ export type SliceMachineHooks = {
|
|
|
192
190
|
|
|
193
191
|
// Slice Libraries
|
|
194
192
|
[SliceMachineHookType.sliceLibrary_read]: Hook<SliceLibraryReadHookBase>;
|
|
195
|
-
[SliceMachineHookType.sliceLibrary_update]: Hook<SliceLibraryUpdateHookBase>;
|
|
196
193
|
|
|
197
194
|
// Custom Types
|
|
198
195
|
[SliceMachineHookType.customType_create]: Hook<CustomTypeCreateHookBase>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ExtendSliceMachineHook, SliceMachinePluginOptions, SliceMachineHook } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* Data provided to `slice-library:update` hook handlers.
|
|
4
|
-
*/
|
|
5
|
-
export type SliceLibraryUpdateHookData = {
|
|
6
|
-
libraryID: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Return value for `slice-library:update` hook handlers.
|
|
10
|
-
*/
|
|
11
|
-
export type SliceLibraryUpdateHookReturnType = void;
|
|
12
|
-
/**
|
|
13
|
-
* Base version of a `slice-library:update` hook handler without plugin runner
|
|
14
|
-
* context.
|
|
15
|
-
*
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export type SliceLibraryUpdateHookBase = SliceMachineHook<SliceLibraryUpdateHookData, SliceLibraryUpdateHookReturnType>;
|
|
19
|
-
/**
|
|
20
|
-
* Handler for the `slice-library:update` hook. The hook is called when a Slice
|
|
21
|
-
* Library needs to be updated (e.g., to regenerate index files).
|
|
22
|
-
*
|
|
23
|
-
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
24
|
-
*/
|
|
25
|
-
export type SliceLibraryUpdateHook<TPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions> = ExtendSliceMachineHook<SliceLibraryUpdateHookBase, TPluginOptions>;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ExtendSliceMachineHook,
|
|
3
|
-
SliceMachinePluginOptions,
|
|
4
|
-
SliceMachineHook,
|
|
5
|
-
} from "../types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Data provided to `slice-library:update` hook handlers.
|
|
9
|
-
*/
|
|
10
|
-
export type SliceLibraryUpdateHookData = {
|
|
11
|
-
libraryID: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Return value for `slice-library:update` hook handlers.
|
|
16
|
-
*/
|
|
17
|
-
export type SliceLibraryUpdateHookReturnType = void;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Base version of a `slice-library:update` hook handler without plugin runner
|
|
21
|
-
* context.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export type SliceLibraryUpdateHookBase = SliceMachineHook<
|
|
26
|
-
SliceLibraryUpdateHookData,
|
|
27
|
-
SliceLibraryUpdateHookReturnType
|
|
28
|
-
>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Handler for the `slice-library:update` hook. The hook is called when a Slice
|
|
32
|
-
* Library needs to be updated (e.g., to regenerate index files).
|
|
33
|
-
*
|
|
34
|
-
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
35
|
-
*/
|
|
36
|
-
export type SliceLibraryUpdateHook<
|
|
37
|
-
TPluginOptions extends SliceMachinePluginOptions = SliceMachinePluginOptions,
|
|
38
|
-
> = ExtendSliceMachineHook<SliceLibraryUpdateHookBase, TPluginOptions>;
|