@velastack/patterns 0.0.16 → 0.0.18

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.
@@ -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-BOXPYvqZ.js";
8
+ import { D as A, M as u } from "./index-DAkiQcTu.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-boRXWhip.js.map
135
+ //# sourceMappingURL=pocketbase-lfpOUvM5.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pocketbase-boRXWhip.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","resolveCommand","serverProcess","spawn"],"mappings":";;;;;;;;AAGO,SAASA,IAAa;AAC3B,SAAO,KAAK,MAAM,KAAK,OAAA,IAAW,GAAK,IAAI;AAC7C;AAGO,SAASC,EACdC,GACAC,GACAC,IAAc,IACC;AACf,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMC,IAAa,MAAM;AACvB,MAAAD;AAEA,YAAME,IAAS,IAAIC,EAAI,OAAA,GAEjBC,IAAU,MAAM;AAGpB,YAFAF,EAAO,QAAA,GAEHF,MAAaH,GAAa;AAC5B,UAAAE;AAAA,YACE,IAAI,MAAM,8BAA8BJ,CAAI,kBAAkB;AAAA,UAAA;AAEhE;AAAA,QACF;AAEA,mBAAWM,GAAY,GAAG;AAAA,MAC5B;AAEA,MAAAC,EAAO,KAAK,SAASE,CAAO,GAE5BF,EAAO,QAAQP,GAAMC,GAAM,MAAM;AAC/B,QAAAM,EAAO,QAAA,GACPJ,EAAA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,IAAAG,EAAA;AAAA,EACF,CAAC;AACH;AAGO,SAASI,EAAcC,GAAaT,IAAc,IAAmB;AAC1E,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMO,IAAY,YAAY;AAC5B,MAAAP;AAEA,UAAI;AAEF,aADiB,MAAM,MAAM,GAAGM,CAAG,aAAa,GACnC,WAAW,KAAK;AAC3B,UAAAR,EAAA;AACA;AAAA,QACF;AAAA,MACF,QAAQ;AAAA,MAER;AAEA,UAAIE,MAAaH,GAAa;AAC5B,QAAAE;AAAA,UACE,IAAI,MAAM,yCAAyCO,CAAG,aAAa;AAAA,QAAA;AAErE;AAAA,MACF;AAEA,iBAAWC,GAAW,GAAG;AAAA,IAC3B;AAEA,IAAAA,EAAA;AAAA,EACF,CAAC;AACH;AClEO,SAASC,EACdC,GACAC,GAC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,IAAI;AAAA,IAAA,GAEd,MAAMM,EAAGN,CAAE;AACX;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;"}
1
+ {"version":3,"file":"pocketbase-lfpOUvM5.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","resolveCommand","serverProcess","spawn"],"mappings":";;;;;;;;AAGO,SAASA,IAAa;AAC3B,SAAO,KAAK,MAAM,KAAK,OAAA,IAAW,GAAK,IAAI;AAC7C;AAGO,SAASC,EACdC,GACAC,GACAC,IAAc,IACC;AACf,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMC,IAAa,MAAM;AACvB,MAAAD;AAEA,YAAME,IAAS,IAAIC,EAAI,OAAA,GAEjBC,IAAU,MAAM;AAGpB,YAFAF,EAAO,QAAA,GAEHF,MAAaH,GAAa;AAC5B,UAAAE;AAAA,YACE,IAAI,MAAM,8BAA8BJ,CAAI,kBAAkB;AAAA,UAAA;AAEhE;AAAA,QACF;AAEA,mBAAWM,GAAY,GAAG;AAAA,MAC5B;AAEA,MAAAC,EAAO,KAAK,SAASE,CAAO,GAE5BF,EAAO,QAAQP,GAAMC,GAAM,MAAM;AAC/B,QAAAM,EAAO,QAAA,GACPJ,EAAA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,IAAAG,EAAA;AAAA,EACF,CAAC;AACH;AAGO,SAASI,EAAcC,GAAaT,IAAc,IAAmB;AAC1E,SAAO,IAAI,QAAQ,CAACC,GAASC,MAAW;AACtC,QAAIC,IAAW;AAEf,UAAMO,IAA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,EAAc,KAAA;AAAA,EAChB;AACF;"}
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
8
8
  summary: string;
9
9
  requires: {
10
10
  auth: false;
11
+ api: false;
11
12
  payments: false;
12
13
  };
13
14
  category: "generators";
@@ -29,6 +30,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
29
30
  summary: string;
30
31
  requires: {
31
32
  auth: false;
33
+ api: false;
32
34
  payments: false;
33
35
  };
34
36
  category: "generators";
@@ -50,6 +52,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
50
52
  summary: string;
51
53
  requires: {
52
54
  auth: false;
55
+ api: false;
53
56
  payments: false;
54
57
  };
55
58
  category: "generators";
@@ -71,6 +74,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
71
74
  summary: string;
72
75
  requires: {
73
76
  auth: false;
77
+ api: false;
74
78
  payments: false;
75
79
  };
76
80
  category: "generators";
@@ -92,6 +96,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
92
96
  summary: string;
93
97
  requires: {
94
98
  auth: false;
99
+ api: false;
95
100
  payments: false;
96
101
  };
97
102
  category: "auth";
@@ -113,6 +118,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
113
118
  summary: string;
114
119
  requires: {
115
120
  auth: false;
121
+ api: false;
116
122
  payments: false;
117
123
  };
118
124
  category: "api";
@@ -124,6 +130,28 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
124
130
  };
125
131
  baseline: "velastack";
126
132
  generate: generate_6;
133
+ } | {
134
+ version: string;
135
+ slug: "enable-api-keys";
136
+ source: string;
137
+ docs: string;
138
+ plan: "open";
139
+ title: string;
140
+ summary: string;
141
+ requires: {
142
+ auth: true;
143
+ api: true;
144
+ payments: false;
145
+ };
146
+ category: "api";
147
+ tags: string[];
148
+ command: {
149
+ raw: string;
150
+ base: string;
151
+ argv: never[];
152
+ };
153
+ baseline: "velastack";
154
+ generate: generate_7;
127
155
  } | {
128
156
  version: string;
129
157
  slug: "enable-i18n";
@@ -134,6 +162,7 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
134
162
  summary: string;
135
163
  requires: {
136
164
  auth: false;
165
+ api: false;
137
166
  payments: false;
138
167
  };
139
168
  category: "i18n";
@@ -144,7 +173,29 @@ export declare const byCategory: Record<"auth" | "generators" | "api" | "i18n",
144
173
  argv: never[];
145
174
  };
146
175
  baseline: "velastack";
147
- generate: generate_7;
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;
148
199
  })[]>;
149
200
 
150
201
  export declare const bySlug: Record<Slug, PatternEntry>;
@@ -155,28 +206,42 @@ declare interface CollectionFieldSpec {
155
206
  name: string;
156
207
  type: string;
157
208
  required?: boolean;
209
+ /** PocketBase collection id for relation fields (runtime). Preview may use the related collection name as a readable stand-in. */
158
210
  collectionId?: string;
159
211
  maxSelect?: number;
212
+ minSelect?: number;
160
213
  values?: string[];
161
214
  onCreate?: boolean;
162
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;
163
224
  }
164
225
 
165
226
  declare interface CollectionSpec {
166
227
  name: string;
167
228
  type: "base" | "auth" | "view";
168
- listRule?: string;
169
- viewRule?: string;
170
- createRule?: string;
171
- updateRule?: string;
172
- deleteRule?: string;
229
+ listRule?: string | null;
230
+ viewRule?: string | null;
231
+ createRule?: string | null;
232
+ updateRule?: string | null;
233
+ deleteRule?: string | null;
173
234
  fields: CollectionFieldSpec[];
235
+ /** View collection SQL (PocketBase). */
236
+ viewQuery?: string;
237
+ indexes?: string[];
174
238
  }
175
239
 
176
240
  declare type Component = string;
177
241
 
178
242
  declare interface Features {
179
243
  auth: boolean;
244
+ api: boolean;
180
245
  payments: boolean;
181
246
  }
182
247
 
@@ -200,6 +265,10 @@ declare function generate_6(options: Options): Promise<Result>;
200
265
 
201
266
  declare function generate_7(options: Options): Promise<Result>;
202
267
 
268
+ declare function generate_8(options: Options): Promise<Result>;
269
+
270
+ declare function generate_9(options: Options): Promise<Result>;
271
+
203
272
  declare interface Options {
204
273
  argv: string[];
205
274
  env: "runtime" | "preview";
@@ -222,6 +291,7 @@ export declare const patterns: ({
222
291
  summary: string;
223
292
  requires: {
224
293
  auth: false;
294
+ api: false;
225
295
  payments: false;
226
296
  };
227
297
  category: "generators";
@@ -243,6 +313,7 @@ export declare const patterns: ({
243
313
  summary: string;
244
314
  requires: {
245
315
  auth: false;
316
+ api: false;
246
317
  payments: false;
247
318
  };
248
319
  category: "generators";
@@ -264,6 +335,7 @@ export declare const patterns: ({
264
335
  summary: string;
265
336
  requires: {
266
337
  auth: false;
338
+ api: false;
267
339
  payments: false;
268
340
  };
269
341
  category: "generators";
@@ -285,6 +357,7 @@ export declare const patterns: ({
285
357
  summary: string;
286
358
  requires: {
287
359
  auth: false;
360
+ api: false;
288
361
  payments: false;
289
362
  };
290
363
  category: "generators";
@@ -306,6 +379,7 @@ export declare const patterns: ({
306
379
  summary: string;
307
380
  requires: {
308
381
  auth: false;
382
+ api: false;
309
383
  payments: false;
310
384
  };
311
385
  category: "auth";
@@ -327,6 +401,7 @@ export declare const patterns: ({
327
401
  summary: string;
328
402
  requires: {
329
403
  auth: false;
404
+ api: false;
330
405
  payments: false;
331
406
  };
332
407
  category: "api";
@@ -338,6 +413,28 @@ export declare const patterns: ({
338
413
  };
339
414
  baseline: "velastack";
340
415
  generate: generate_6;
416
+ } | {
417
+ version: string;
418
+ slug: "enable-api-keys";
419
+ source: string;
420
+ docs: string;
421
+ plan: "open";
422
+ title: string;
423
+ summary: string;
424
+ requires: {
425
+ auth: true;
426
+ api: true;
427
+ payments: false;
428
+ };
429
+ category: "api";
430
+ tags: string[];
431
+ command: {
432
+ raw: string;
433
+ base: string;
434
+ argv: never[];
435
+ };
436
+ baseline: "velastack";
437
+ generate: generate_7;
341
438
  } | {
342
439
  version: string;
343
440
  slug: "enable-i18n";
@@ -348,6 +445,7 @@ export declare const patterns: ({
348
445
  summary: string;
349
446
  requires: {
350
447
  auth: false;
448
+ api: false;
351
449
  payments: false;
352
450
  };
353
451
  category: "i18n";
@@ -358,7 +456,29 @@ export declare const patterns: ({
358
456
  argv: never[];
359
457
  };
360
458
  baseline: "velastack";
361
- generate: generate_7;
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;
362
482
  })[];
363
483
 
364
484
  declare interface Result {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b as r, a as e, p as o, v as t } from "./chunks/index-BOXPYvqZ.js";
1
+ import { b as r, a as e, p as o, v as t } from "./chunks/index-DAkiQcTu.js";
2
2
  export {
3
3
  r as byCategory,
4
4
  e as bySlug,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velastack/patterns",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -1,38 +0,0 @@
1
- import { readFileSync as s } from "node:fs";
2
- import { l as c } from "./index-BOXPYvqZ.js";
3
- import { w as l, g as u } from "./pocketbase-boRXWhip.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-g6OYst1X.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collections-g6OYst1X.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;"}