@velastack/patterns 0.0.29 → 0.0.31

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.
Files changed (47) hide show
  1. package/dist/chunks/collections-BRIAYJ-Q.js +94 -0
  2. package/dist/chunks/collections-BRIAYJ-Q.js.map +1 -0
  3. package/dist/chunks/{constants-B5Ub2oFy.js → constants-BMZmCRiI.js} +1 -1
  4. package/dist/chunks/{constants-B5Ub2oFy.js.map → constants-BMZmCRiI.js.map} +1 -1
  5. package/dist/chunks/{dedent-BFNYR8cb.js → dedent-C4qKBQXh.js} +1 -1
  6. package/dist/chunks/{dedent-BFNYR8cb.js.map → dedent-C4qKBQXh.js.map} +1 -1
  7. package/dist/chunks/{env.preview-kw0hC6y8.js → env.preview-NYMljYNr.js} +1 -1
  8. package/dist/chunks/{env.preview-kw0hC6y8.js.map → env.preview-NYMljYNr.js.map} +1 -1
  9. package/dist/chunks/{env.runtime-CJS54CZX.js → env.runtime-ZUZgxjxf.js} +2 -2
  10. package/dist/chunks/{env.runtime-CJS54CZX.js.map → env.runtime-ZUZgxjxf.js.map} +1 -1
  11. package/dist/chunks/errors-Co77I4oK.js +10 -0
  12. package/dist/chunks/errors-Co77I4oK.js.map +1 -0
  13. package/dist/chunks/{generate.runtime-V7jzalbO.js → generate.runtime-4zd9-8H_.js} +17 -16
  14. package/dist/chunks/{generate.runtime-V7jzalbO.js.map → generate.runtime-4zd9-8H_.js.map} +1 -1
  15. package/dist/chunks/{generate.runtime-B3WXGKZY.js → generate.runtime-BKrtBCRk.js} +14 -13
  16. package/dist/chunks/{generate.runtime-B3WXGKZY.js.map → generate.runtime-BKrtBCRk.js.map} +1 -1
  17. package/dist/chunks/{generate.runtime-CzKWz6BN.js → generate.runtime-BkjQiaP_.js} +12 -11
  18. package/dist/chunks/{generate.runtime-CzKWz6BN.js.map → generate.runtime-BkjQiaP_.js.map} +1 -1
  19. package/dist/chunks/{generate.runtime-DVRoiEhh.js → generate.runtime-CXqD8em8.js} +189 -132
  20. package/dist/chunks/{generate.runtime-DVRoiEhh.js.map → generate.runtime-CXqD8em8.js.map} +1 -1
  21. package/dist/chunks/{generate.runtime-Bhqdiykw.js → generate.runtime-CbiQhqdL.js} +5 -4
  22. package/dist/chunks/{generate.runtime-Bhqdiykw.js.map → generate.runtime-CbiQhqdL.js.map} +1 -1
  23. package/dist/chunks/generate.runtime-DpeB3h-P.js +293 -0
  24. package/dist/chunks/generate.runtime-DpeB3h-P.js.map +1 -0
  25. package/dist/chunks/{generate.runtime-BS_l-k-A.js → generate.runtime-uk9-KOP-.js} +19 -18
  26. package/dist/chunks/{generate.runtime-BS_l-k-A.js.map → generate.runtime-uk9-KOP-.js.map} +1 -1
  27. package/dist/chunks/{modify-file-Drki52pc.js → modify-file-D3OuKUEp.js} +3 -3
  28. package/dist/chunks/{modify-file-Drki52pc.js.map → modify-file-D3OuKUEp.js.map} +1 -1
  29. package/dist/chunks/modify-svelte-config-remote-Dzgk1OIN.js +128 -0
  30. package/dist/chunks/modify-svelte-config-remote-Dzgk1OIN.js.map +1 -0
  31. package/dist/chunks/{pocketbase-CDu4GzZD.js → pocketbase--dNkFDJ5.js} +1 -1
  32. package/dist/chunks/{pocketbase-CDu4GzZD.js.map → pocketbase--dNkFDJ5.js.map} +1 -1
  33. package/dist/chunks/{pocketbase-CmKcAXDf.js → pocketbase-W_FJaYZ3.js} +3 -3
  34. package/dist/chunks/{pocketbase-CmKcAXDf.js.map → pocketbase-W_FJaYZ3.js.map} +1 -1
  35. package/dist/chunks/{ts-morph-helpers-BMxk6lHK.js → ts-morph-helpers-digNcfBD.js} +1 -1
  36. package/dist/chunks/{ts-morph-helpers-BMxk6lHK.js.map → ts-morph-helpers-digNcfBD.js.map} +1 -1
  37. package/dist/chunks/{util-k-qPjL06.js → util-C064WO8o.js} +4 -3
  38. package/dist/chunks/{util-k-qPjL06.js.map → util-C064WO8o.js.map} +1 -1
  39. package/dist/chunks/{write-result-C3SCX65t.js → write-result-C80dpjr-.js} +1 -1
  40. package/dist/chunks/{write-result-C3SCX65t.js.map → write-result-C80dpjr-.js.map} +1 -1
  41. package/dist/index.d.ts +156 -20
  42. package/dist/index.js +1430 -1004
  43. package/dist/index.js.map +1 -1
  44. package/package.json +1 -1
  45. package/dist/chunks/collections-CwH8DO-2.js +0 -54
  46. package/dist/chunks/collections-CwH8DO-2.js.map +0 -1
  47. /package/dist/chunks/{taggedTemplateLiteral-BLWebVbJ.js → taggedTemplateLiteral-Bfbldyfk.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velastack/patterns",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -1,54 +0,0 @@
1
- import { n as e } from "./util-k-qPjL06.js";
2
- import { n as t, r as n, t as r } from "./pocketbase-CmKcAXDf.js";
3
- import { readFileSync as i } from "node:fs";
4
- //#region src/runtime/collections.ts
5
- function a(e) {
6
- if (e.response?.data?.name?.code === "validation_not_unique") return !0;
7
- let t = e.message?.toLowerCase() ?? "";
8
- return t.includes("already exists") || t.includes("must be unique");
9
- }
10
- function o(e) {
11
- let t = {};
12
- return e.listRule !== void 0 && (t.listRule = e.listRule), e.viewRule !== void 0 && (t.viewRule = e.viewRule), e.createRule !== void 0 && (t.createRule = e.createRule), e.updateRule !== void 0 && (t.updateRule = e.updateRule), e.deleteRule !== void 0 && (t.deleteRule = e.deleteRule), t;
13
- }
14
- async function s(n, a, s) {
15
- let c = [];
16
- for (let l of a) {
17
- let a = l.collectionName.replace(/'/g, "''"), u = await n.collections.getFirstListItem(`name='${a}'`);
18
- if (await n.collections.update(u.id, o(l)), await t(), s) {
19
- let t = r(l.collectionName, "updated", s);
20
- t && c.push({
21
- path: t,
22
- language: e(t),
23
- content: i(t, "utf8"),
24
- status: "success"
25
- });
26
- }
27
- }
28
- return c;
29
- }
30
- async function c(o, s) {
31
- if (o.length === 0) return [];
32
- let c = [];
33
- return await n(s.root, async (n) => {
34
- for (let l of o) {
35
- try {
36
- await n.collections.create(l);
37
- } catch (e) {
38
- throw a(e) ? Error(`Collection "${l.name}" already exists. Choose a different model name or remove the existing collection first.`) : e;
39
- }
40
- await t();
41
- let o = r(l.name, "created", s);
42
- o && c.push({
43
- path: o,
44
- language: e(o),
45
- content: i(o, "utf8"),
46
- status: "success"
47
- });
48
- }
49
- }), c;
50
- }
51
- //#endregion
52
- export { s as applyCollectionRulePatches, c as createCollections };
53
-
54
- //# sourceMappingURL=collections-CwH8DO-2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collections-CwH8DO-2.js","names":[],"sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type {\n CollectionRulesPatch,\n CollectionSpec,\n File,\n Options,\n} from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { getMigrationFile, migrationDelay, withPocketbase } from \"./pocketbase\";\n\ninterface PocketBaseCollectionCreateError {\n response?: {\n data?: {\n name?: {\n code?: string;\n };\n };\n };\n message?: string;\n}\n\nfunction isCollectionAlreadyExistsError(\n error: PocketBaseCollectionCreateError,\n): boolean {\n if (error.response?.data?.name?.code === \"validation_not_unique\") {\n return true;\n }\n\n const message = error.message?.toLowerCase() ?? \"\";\n return (\n message.includes(\"already exists\") || message.includes(\"must be unique\")\n );\n}\n\nfunction rulePayloadFromPatch(\n patch: CollectionRulesPatch,\n): Record<string, unknown> {\n const payload: Record<string, unknown> = {};\n if (patch.listRule !== undefined) payload.listRule = patch.listRule;\n if (patch.viewRule !== undefined) payload.viewRule = patch.viewRule;\n if (patch.createRule !== undefined) payload.createRule = patch.createRule;\n if (patch.updateRule !== undefined) payload.updateRule = patch.updateRule;\n if (patch.deleteRule !== undefined) payload.deleteRule = patch.deleteRule;\n return payload;\n}\n\n/**\n * Applies API rule updates in array order. Call after all referenced collections exist.\n * Collects migration files produced by each update when `options` is provided.\n */\nexport async function applyCollectionRulePatches(\n pb: {\n collections: {\n getFirstListItem: (filter: string) => Promise<{ id: string }>;\n update: (id: string, body: Record<string, unknown>) => Promise<unknown>;\n };\n },\n patches: CollectionRulesPatch[],\n options?: Options,\n): Promise<File[]> {\n const migrations: File[] = [];\n\n for (const patch of patches) {\n const escaped = patch.collectionName.replace(/'/g, \"''\");\n const col = await pb.collections.getFirstListItem(`name='${escaped}'`);\n await pb.collections.update(col.id, rulePayloadFromPatch(patch));\n await migrationDelay();\n\n if (options) {\n const migrationFile = getMigrationFile(\n patch.collectionName,\n \"updated\",\n options,\n );\n if (migrationFile) {\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n }\n }\n\n return migrations;\n}\n\nexport async function createCollections(\n collections: CollectionSpec[],\n options: Options,\n): Promise<File[]> {\n if (collections.length === 0) {\n return [];\n }\n\n const migrations: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n for (const collection of collections) {\n try {\n await pb.collections.create(collection);\n } catch (error) {\n if (\n isCollectionAlreadyExistsError(\n error as PocketBaseCollectionCreateError,\n )\n ) {\n throw new Error(\n `Collection \"${collection.name}\" already exists. Choose a different model name or remove the existing collection first.`,\n );\n }\n throw error;\n }\n await migrationDelay();\n\n const migrationFile = getMigrationFile(\n collection.name,\n \"created\",\n options,\n );\n if (!migrationFile) {\n continue;\n }\n\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n return migrations;\n}\n"],"mappings":";;;;AAqBA,SAAS,EACP,GACS;AACT,KAAI,EAAM,UAAU,MAAM,MAAM,SAAS,wBACvC,QAAO;CAGT,IAAM,IAAU,EAAM,SAAS,aAAa,IAAI;AAChD,QACE,EAAQ,SAAS,iBAAiB,IAAI,EAAQ,SAAS,iBAAiB;;AAI5E,SAAS,EACP,GACyB;CACzB,IAAM,IAAmC,EAAE;AAM3C,QAL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