@velastack/patterns 0.0.17 → 0.0.19
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/chunks/collections-CAafgIoZ.js +62 -0
- package/dist/chunks/collections-CAafgIoZ.js.map +1 -0
- package/dist/chunks/{env.runtime-BGG6V4qg.js → env.runtime-C3E02sUH.js} +2 -2
- package/dist/chunks/{env.runtime-BGG6V4qg.js.map → env.runtime-C3E02sUH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CL_SU1wV.js → generate.runtime-C7YhHvlr.js} +3 -3
- package/dist/chunks/{generate.runtime-CL_SU1wV.js.map → generate.runtime-C7YhHvlr.js.map} +1 -1
- package/dist/chunks/generate.runtime-DBTOrhnc.js +633 -0
- package/dist/chunks/generate.runtime-DBTOrhnc.js.map +1 -0
- package/dist/chunks/{generate.runtime-DDZCukG0.js → generate.runtime-DgtB6hP4.js} +2 -2
- package/dist/chunks/{generate.runtime-DDZCukG0.js.map → generate.runtime-DgtB6hP4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BjFzQdEe.js → generate.runtime-DoQkjIdl.js} +2 -2
- package/dist/chunks/{generate.runtime-BjFzQdEe.js.map → generate.runtime-DoQkjIdl.js.map} +1 -1
- package/dist/chunks/{index-ZTxLoBuU.js → index-E6LAzq1d.js} +3735 -784
- package/dist/chunks/index-E6LAzq1d.js.map +1 -0
- package/dist/chunks/{pocketbase-CtWkx70o.js → pocketbase-BCvqw1Cr.js} +2 -2
- package/dist/chunks/{pocketbase-CtWkx70o.js.map → pocketbase-BCvqw1Cr.js.map} +1 -1
- package/dist/index.d.ts +64 -5
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/dist/chunks/collections-BQ2vnlIE.js +0 -38
- package/dist/chunks/collections-BQ2vnlIE.js.map +0 -1
- package/dist/chunks/index-ZTxLoBuU.js.map +0 -1
|
@@ -5,7 +5,7 @@ import { detect as y } from "package-manager-detector";
|
|
|
5
5
|
import { resolveCommand as k } from "package-manager-detector/commands";
|
|
6
6
|
import _ from "cross-spawn";
|
|
7
7
|
import R from "node:net";
|
|
8
|
-
import { D as A, M as u } from "./index-
|
|
8
|
+
import { D as A, M as u } from "./index-E6LAzq1d.js";
|
|
9
9
|
function b() {
|
|
10
10
|
return Math.floor(Math.random() * 1e4) + 1e4;
|
|
11
11
|
}
|
|
@@ -132,4 +132,4 @@ export {
|
|
|
132
132
|
I as g,
|
|
133
133
|
W as w
|
|
134
134
|
};
|
|
135
|
-
//# sourceMappingURL=pocketbase-
|
|
135
|
+
//# sourceMappingURL=pocketbase-BCvqw1Cr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pocketbase-
|
|
1
|
+
{"version":3,"file":"pocketbase-BCvqw1Cr.js","sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n// Generate a random port\nexport function randomPort() {\n return Math.floor(Math.random() * 10000) + 10000;\n}\n\n// Wait for the port to be available\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 10,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 10): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n } catch {\n // Ignore fetch errors and continue retrying\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for health check at ${url}/api/health`),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { randomPort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = randomPort();\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process\n const serverProcess = spawn(command, args, {\n stdio: \"ignore\",\n });\n\n try {\n // Wait for the server to be ready\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process\n serverProcess.kill();\n }\n}\n"],"names":["randomPort","waitForPort","port","host","maxAttempts","resolve","reject","attempts","tryConnect","socket","net","onError","waitForHealth","url","tryHealth","getMigrationFile","collectionName","action","options","ending","migrationFile","readdirSync","path","MIGRATIONS_DIR","file","getPocketbaseMetadata","cwd","metadataPath","existsSync","readFileSync","authWithRetries","pb","email","password","authSuccess","attempt","withPocketbase","fn","dir","DATA_DIR","migrationsDir","metadata","PocketBase","commandArgs","packageManager","_a","detect","command","args","resolve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;AAAA,EACF;AAGF,QAAM7B,IAAOF,EAAA,GACP2C,IAAc;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACAL;AAAA,IACA;AAAA,IACAE;AAAA,IACA;AAAA,IACA,GAAGrC,CAAI,IAAID,CAAI;AAAA,EAAA,GAGX0C,MAAkBC,IAAA,MAAMC,EAAO,EAAE,KAAApB,EAAA,CAAK,MAApB,gBAAAmB,EAAwB,SAAQ,OAClD,EAAE,SAAAE,GAAS,MAAAC,EAAA,IAASC;AAAA,IACxBL;AAAA,IACA;AAAA,IACAD;AAAA,EAAA;AAIF,EAAIC,MAAmB,SAAOI,EAAK,QAAQ,OAAO;AAGlD,QAAME,IAAgBC,EAAMJ,GAASC,GAAM;AAAA,IACzC,OAAO;AAAA,EAAA,CACR;AAED,MAAI;AAEF,UAAM/C,EAAYC,GAAMC,CAAI,GAC5B,MAAMS,EAAc,UAAUT,CAAI,IAAID,CAAI,EAAE;AAE5C,UAAM6B,IAAK,IAAIW,EAAW,UAAUvC,CAAI,IAAID,CAAI,EAAE;AAClD,UAAM4B;AAAA,MACJC;AAAA,MACA,QAAQ,IAAI;AAAA,MACZ,QAAQ,IAAI;AAAA,IAAA,GAEd,MAAMM,EAAGN,CAAE;AAAA,EACb,UAAA;AAEE,IAAAmB,EAAc,KAAA;AAAA,EAChB;AACF;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -174,6 +174,28 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
|
|
|
174
174
|
};
|
|
175
175
|
baseline: "velastack";
|
|
176
176
|
generate: generate_8;
|
|
177
|
+
} | {
|
|
178
|
+
version: string;
|
|
179
|
+
slug: "enable-teams";
|
|
180
|
+
source: string;
|
|
181
|
+
docs: string;
|
|
182
|
+
plan: "pro";
|
|
183
|
+
title: string;
|
|
184
|
+
summary: string;
|
|
185
|
+
requires: {
|
|
186
|
+
auth: true;
|
|
187
|
+
api: false;
|
|
188
|
+
payments: false;
|
|
189
|
+
};
|
|
190
|
+
category: "auth";
|
|
191
|
+
tags: string[];
|
|
192
|
+
command: {
|
|
193
|
+
raw: string;
|
|
194
|
+
base: string;
|
|
195
|
+
argv: never[];
|
|
196
|
+
};
|
|
197
|
+
baseline: "velastack";
|
|
198
|
+
generate: generate_9;
|
|
177
199
|
})[]>;
|
|
178
200
|
|
|
179
201
|
export declare const bySlug: Record<Slug, PatternEntry>;
|
|
@@ -184,22 +206,35 @@ declare interface CollectionFieldSpec {
|
|
|
184
206
|
name: string;
|
|
185
207
|
type: string;
|
|
186
208
|
required?: boolean;
|
|
209
|
+
/** PocketBase collection id for relation fields (runtime). Preview may use the related collection name as a readable stand-in. */
|
|
187
210
|
collectionId?: string;
|
|
188
211
|
maxSelect?: number;
|
|
212
|
+
minSelect?: number;
|
|
189
213
|
values?: string[];
|
|
190
214
|
onCreate?: boolean;
|
|
191
215
|
onUpdate?: boolean;
|
|
216
|
+
primaryKey?: boolean;
|
|
217
|
+
cascadeDelete?: boolean;
|
|
218
|
+
pattern?: string;
|
|
219
|
+
min?: number;
|
|
220
|
+
max?: number;
|
|
221
|
+
autogeneratePattern?: string;
|
|
222
|
+
exceptDomains?: null;
|
|
223
|
+
onlyDomains?: null;
|
|
192
224
|
}
|
|
193
225
|
|
|
194
226
|
declare interface CollectionSpec {
|
|
195
227
|
name: string;
|
|
196
228
|
type: "base" | "auth" | "view";
|
|
197
|
-
listRule?: string;
|
|
198
|
-
viewRule?: string;
|
|
199
|
-
createRule?: string;
|
|
200
|
-
updateRule?: string;
|
|
201
|
-
deleteRule?: string;
|
|
229
|
+
listRule?: string | null;
|
|
230
|
+
viewRule?: string | null;
|
|
231
|
+
createRule?: string | null;
|
|
232
|
+
updateRule?: string | null;
|
|
233
|
+
deleteRule?: string | null;
|
|
202
234
|
fields: CollectionFieldSpec[];
|
|
235
|
+
/** View collection SQL (PocketBase). */
|
|
236
|
+
viewQuery?: string;
|
|
237
|
+
indexes?: string[];
|
|
203
238
|
}
|
|
204
239
|
|
|
205
240
|
declare type Component = string;
|
|
@@ -232,6 +267,8 @@ declare function generate_7(options: Options): Promise<Result>;
|
|
|
232
267
|
|
|
233
268
|
declare function generate_8(options: Options): Promise<Result>;
|
|
234
269
|
|
|
270
|
+
declare function generate_9(options: Options): Promise<Result>;
|
|
271
|
+
|
|
235
272
|
declare interface Options {
|
|
236
273
|
argv: string[];
|
|
237
274
|
env: "runtime" | "preview";
|
|
@@ -420,6 +457,28 @@ export declare const patterns: ({
|
|
|
420
457
|
};
|
|
421
458
|
baseline: "velastack";
|
|
422
459
|
generate: generate_8;
|
|
460
|
+
} | {
|
|
461
|
+
version: string;
|
|
462
|
+
slug: "enable-teams";
|
|
463
|
+
source: string;
|
|
464
|
+
docs: string;
|
|
465
|
+
plan: "pro";
|
|
466
|
+
title: string;
|
|
467
|
+
summary: string;
|
|
468
|
+
requires: {
|
|
469
|
+
auth: true;
|
|
470
|
+
api: false;
|
|
471
|
+
payments: false;
|
|
472
|
+
};
|
|
473
|
+
category: "auth";
|
|
474
|
+
tags: string[];
|
|
475
|
+
command: {
|
|
476
|
+
raw: string;
|
|
477
|
+
base: string;
|
|
478
|
+
argv: never[];
|
|
479
|
+
};
|
|
480
|
+
baseline: "velastack";
|
|
481
|
+
generate: generate_9;
|
|
423
482
|
})[];
|
|
424
483
|
|
|
425
484
|
declare interface Result {
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velastack/patterns",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"build": "vite build",
|
|
13
13
|
"dev": "vite build --watch",
|
|
14
14
|
"clean": "rm -rf dist",
|
|
15
|
-
"test": "vitest run",
|
|
16
|
-
"test:watch": "vitest --watch",
|
|
17
|
-
"test:integration": "vitest run
|
|
15
|
+
"test": "vitest run --exclude **/integration.test.ts",
|
|
16
|
+
"test:watch": "vitest --watch --exclude **/integration.test.ts",
|
|
17
|
+
"test:integration": "vitest run **/integration.test.ts"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"prettier": "^3.8.2",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readFileSync as s } from "node:fs";
|
|
2
|
-
import { l as c } from "./index-ZTxLoBuU.js";
|
|
3
|
-
import { w as l, g as u } from "./pocketbase-CtWkx70o.js";
|
|
4
|
-
function m(o) {
|
|
5
|
-
var n, a, t, e;
|
|
6
|
-
if (((t = (a = (n = o.response) == null ? void 0 : n.data) == null ? void 0 : a.name) == null ? void 0 : t.code) === "validation_not_unique")
|
|
7
|
-
return !0;
|
|
8
|
-
const r = ((e = o.message) == null ? void 0 : e.toLowerCase()) ?? "";
|
|
9
|
-
return r.includes("already exists") || r.includes("must be unique");
|
|
10
|
-
}
|
|
11
|
-
async function h(o, r) {
|
|
12
|
-
if (o.length === 0)
|
|
13
|
-
return [];
|
|
14
|
-
const n = [];
|
|
15
|
-
return await l(r.root, async (a) => {
|
|
16
|
-
for (const t of o) {
|
|
17
|
-
try {
|
|
18
|
-
await a.collections.create(t);
|
|
19
|
-
} catch (i) {
|
|
20
|
-
throw m(
|
|
21
|
-
i
|
|
22
|
-
) ? new Error(
|
|
23
|
-
`Collection "${t.name}" already exists. Choose a different model name or remove the existing collection first.`
|
|
24
|
-
) : i;
|
|
25
|
-
}
|
|
26
|
-
const e = u(t.name, "created", r);
|
|
27
|
-
e && n.push({
|
|
28
|
-
path: e,
|
|
29
|
-
language: c(e),
|
|
30
|
-
content: s(e, "utf8")
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}), n;
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
h as createCollections
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=collections-BQ2vnlIE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections-BQ2vnlIE.js","sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type { CollectionSpec, File, Options } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { getMigrationFile, 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 message.includes(\"already exists\") || message.includes(\"must be unique\");\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\n const migrationFile = getMigrationFile(collection.name, \"created\", options);\n if (!migrationFile) {\n continue;\n }\n\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n });\n }\n });\n\n return migrations;\n}\n"],"names":["isCollectionAlreadyExistsError","error","_c","_b","_a","message","_d","createCollections","collections","options","migrations","withPocketbase","pb","collection","migrationFile","getMigrationFile","languageFromPath","readFileSync"],"mappings":";;;AAgBA,SAASA,EACPC,GACS;;AACT,QAAIC,KAAAC,KAAAC,IAAAH,EAAM,aAAN,gBAAAG,EAAgB,SAAhB,gBAAAD,EAAsB,SAAtB,gBAAAD,EAA4B,UAAS;AACvC,WAAO;AAGT,QAAMG,MAAUC,IAAAL,EAAM,YAAN,gBAAAK,EAAe,kBAAiB;AAChD,SAAOD,EAAQ,SAAS,gBAAgB,KAAKA,EAAQ,SAAS,gBAAgB;AAChF;AAEA,eAAsBE,EACpBC,GACAC,GACiB;AACjB,MAAID,EAAY,WAAW;AACzB,WAAO,CAAA;AAGT,QAAME,IAAqB,CAAA;AAE3B,eAAMC,EAAeF,EAAQ,MAAM,OAAOG,MAAO;AAC/C,eAAWC,KAAcL,GAAa;AACpC,UAAI;AACF,cAAMI,EAAG,YAAY,OAAOC,CAAU;AAAA,MACxC,SAASZ,GAAO;AACd,cACED;AAAA,UACEC;AAAA,QAAA,IAGI,IAAI;AAAA,UACR,eAAeY,EAAW,IAAI;AAAA,QAAA,IAG5BZ;AAAA,MACR;AAEA,YAAMa,IAAgBC,EAAiBF,EAAW,MAAM,WAAWJ,CAAO;AAC1E,MAAKK,KAILJ,EAAW,KAAK;AAAA,QACd,MAAMI;AAAA,QACN,UAAUE,EAAiBF,CAAa;AAAA,QACxC,SAASG,EAAaH,GAAe,MAAM;AAAA,MAAA,CAC5C;AAAA,IACH;AAAA,EACF,CAAC,GAEMJ;AACT;"}
|