@stacksjs/actions 0.70.83 → 0.70.85
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/action.js +1 -1
- package/dist/actions.js +1 -1
- package/dist/add.js +1 -1
- package/dist/ai/request-model-access.js +1 -1
- package/dist/blog.js +1 -1
- package/dist/build/frontend-static.js +1 -1
- package/dist/build.js +1 -1
- package/dist/chunk-0c8sd1t6.js +2 -0
- package/dist/{chunk-hv8tkjw2.js → chunk-0g2nzhx9.js} +2 -2
- package/dist/chunk-0gadhvn7.js +3 -0
- package/dist/{chunk-9sx16wyz.js → chunk-0h27aa4r.js} +1 -1
- package/dist/{chunk-f8z1aft6.js → chunk-3peh8kqs.js} +1 -1
- package/dist/{chunk-73y0wp0s.js → chunk-62gdfav8.js} +2 -2
- package/dist/{chunk-d5mbs5zz.js → chunk-6bk53y02.js} +1 -1
- package/dist/{chunk-dxvgx0r7.js → chunk-78c5n3s2.js} +2 -2
- package/dist/{chunk-heh4x32p.js → chunk-c74qv38e.js} +2 -2
- package/dist/{chunk-rft5b6wr.js → chunk-e142dheq.js} +1 -1
- package/dist/{chunk-k7n6c9hm.js → chunk-ec4gky40.js} +1 -1
- package/dist/chunk-h3d81wrg.js +3 -0
- package/dist/{chunk-hr9ndn21.js → chunk-m3q0x4h0.js} +1 -1
- package/dist/{chunk-30cc35np.js → chunk-mqgbyhph.js} +1 -1
- package/dist/{chunk-t5j470r2.js → chunk-n5eqwhck.js} +2 -2
- package/dist/{chunk-8maaf0ze.js → chunk-nsvnqv8y.js} +2 -2
- package/dist/{chunk-w363nwy3.js → chunk-nty6mmx4.js} +1 -1
- package/dist/{chunk-h10aj7jf.js → chunk-tpb8jgsk.js} +2 -2
- package/dist/{chunk-wtnp31q5.js → chunk-tsbk5vne.js} +1 -1
- package/dist/{chunk-w4erevzw.js → chunk-y6e448he.js} +2 -2
- package/dist/commit.js +1 -1
- package/dist/deploy/index.js +2 -2
- package/dist/dev/api.js +1 -1
- package/dist/dev/dashboard-globals.js +1 -1
- package/dist/dev/dashboard-utils.js +1 -1
- package/dist/dev/dashboard.js +1 -1
- package/dist/dev/index.js +1 -1
- package/dist/dev/migrate-watcher.js +1 -1
- package/dist/dev/views.js +1 -1
- package/dist/discover-packages.js +1 -1
- package/dist/examples.js +1 -1
- package/dist/generate/component-meta.js +1 -1
- package/dist/generate/env-files.js +1 -1
- package/dist/generate/ide-helpers.js +1 -1
- package/dist/generate/index.js +1 -1
- package/dist/generate/lib-entries.js +1 -1
- package/dist/generate/vscode-custom-data.js +1 -1
- package/dist/helpers/component-meta.js +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/lib-entries.js +1 -1
- package/dist/helpers/package-json.js +1 -1
- package/dist/helpers/utils.js +1 -1
- package/dist/helpers/vscode-custom-data.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lint/fix.js +1 -1
- package/dist/lint/index.js +1 -1
- package/dist/lint/lint.js +1 -1
- package/dist/make-command.js +44 -1
- package/dist/make-job.js +128 -1
- package/dist/make-policy.js +93 -1
- package/dist/make-resource.js +112 -1
- package/dist/make.js +1 -1
- package/dist/orm/base.js +1 -1
- package/dist/release.js +1 -1
- package/dist/run-action.js +1 -1
- package/dist/scaffold-crud.js +86 -1
- package/dist/setup/index.js +1 -1
- package/dist/setup/ssl.js +1 -1
- package/dist/stacks.js +1 -1
- package/dist/templates.js +1 -1
- package/dist/types.js +1 -1
- package/dist/upgrade/dependencies.js +1 -1
- package/dist/upgrade/framework-utils.js +1 -1
- package/dist/upgrade/framework.js +1 -1
- package/dist/upgrade/index.js +1 -1
- package/dist/upgrade/packages.js +1 -1
- package/dist/upgrade.js +1 -1
- package/package.json +17 -16
- package/dist/chunk-0wyxyqak.js +0 -3
- package/dist/chunk-8kvzjd10.js +0 -3
- package/dist/chunk-acyw294f.js +0 -130
- package/dist/chunk-ay41a7jn.js +0 -3
- package/dist/chunk-e87s6b8r.js +0 -46
- package/dist/chunk-g6k41p49.js +0 -1
- package/dist/chunk-gcjrdkq7.js +0 -95
- package/dist/chunk-h63c1v89.js +0 -3
- package/dist/chunk-n057zfgw.js +0 -114
- package/dist/chunk-v0hqskdk.js +0 -3
- package/dist/chunk-vv4nqhgg.js +0 -3
- package/dist/chunk-x0cnhg3z.js +0 -88
package/dist/chunk-8kvzjd10.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{pb as j,qb as D}from"./chunk-v0hqskdk.js";var u={};j(u,{runActions:()=>A,runAction:()=>v,hasAction:()=>S});import{existsSync as W}from"fs";import T from"process";import{buddyOptions as I,runCommand as F,runCommands as N}from"@stacksjs/cli";import{err as X}from"@stacksjs/error-handling";import{log as V}from"@stacksjs/logging";import*as B from"@stacksjs/path";async function x(q){let z=[];z.push(B.actionsPath(`src/${q}.ts`));try{let H=import.meta.resolve("@stacksjs/actions/package.json");if(H){let J=new URL(H).pathname,G=J.slice(0,J.lastIndexOf("/"));z.push(`${G}/dist/${q}.js`),z.push(`${G}/dist/src/${q}.js`),z.push(`${G}/src/${q}.ts`)}}catch{}for(let H of z)if(await Bun.file(H).exists())return H;return null}async function v(q,z){if(V.debug(`[action] Running: ${q}`),q==="dev/views")try{let K=B.projectPath("pantry");if(!T.env.NODE_PATH?.includes(K))T.env.NODE_PATH=T.env.NODE_PATH?`${K}:${T.env.NODE_PATH}`:K,D("module").Module._initPaths?.();let Z=[B.projectPath("storage/framework/core/actions/src/dev/views.ts"),B.frameworkPath("actions/src/dev/views.ts")];for(let Q of Z)if(W(Q))return await import(Q),{ok:!0,value:{}};return X("dev/views entry not found")}catch(K){return X(`Failed to start dev server: ${K}`)}if(!(q.includes("/")||["dev","build","install","upgrade","migrate"].some((K)=>q.startsWith(K)))){let K=new Bun.Glob("**/*.{ts,js}"),Z={cwd:B.userActionsPath(),onlyFiles:!0,absolute:!0},Q=[],b=B.userActionsPath();for await(let L of K.scan(Z)){if(L.replace(`${b}/`,"").replace(/\.(ts|js)$/,"")===q||L.endsWith(`${q}.ts`)||L.endsWith(`${q}.js`))return V.debug(`[action] Resolved: ${q} \u2192 ${L}`),await(await import(L)).default.handle(void 0);Q.push(L)}for(let L of Q)try{let Y=await import(L);if(Y.name===q)return V.debug(`[action] Resolved: ${q} \u2192 ${L}`),await Y.handle()}catch(Y){}}let J=await x(q);if(!J)return X(`Action '${q}' not found in storage/framework/core/actions/src or @stacksjs/actions`);V.debug(`[action] Resolved: ${q} \u2192 ${J}`);let G=q.startsWith("dev/"),M=G?"--watch":"",U=G?"":I(z)||"",w=`bun ${M} ${J} ${U}`.trimEnd(),_=B.projectPath("pantry"),$=T.env.NODE_PATH,C=$?`${_}:${$}`:_,E=z?.verbose||G&&!z?.quiet,O={cwd:z?.cwd||B.projectPath(),...z,stdout:E?"inherit":void 0,stderr:E?"inherit":void 0,env:{...z?.env,NODE_PATH:C,...G?{STACKS_DEV_SERVER:"1"}:{}}},R=await F(w,O);return V.debug(`[action] Completed: ${q}`),R}async function A(q,z){if(!q.length)return X("No actions were specified");for(let M of q)if(!S(M))return X(`The specified action "${M}" does not exist`);let H=I(z)||"",J={cwd:z?.cwd||B.projectPath(),...z},G=q.map((M)=>`bun ${B.relativeActionsPath(`src/${M}.ts`)} ${H}`);return await N(G,J)}function S(q){let z=[`${q}.ts`,`${q}`,`Dashboard/${q}.ts`,`Dashboard/${q}`,`Buddy/${q}.ts`,`Buddy/${q}`],H=[`src/${q}.ts`,`src/${q}`,`${q}.ts`,`${q}`];return[...z.map((G)=>B.userActionsPath(G)),...H.map((G)=>B.actionsPath(G))].some((G)=>W(G))}
|
|
3
|
-
export{v as gb,A as hb,S as ib,u as jb};
|
package/dist/chunk-acyw294f.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{log as A}from"@stacksjs/logging";import*as H from"@stacksjs/path";import{writeFile as L}from"@stacksjs/storage";async function T(v){let x=v,y=v.name;if(!y)return A.error("Job name is required"),!1;let z=y.endsWith("Job")?y:`${y}Job`,I=x.class??!1?Q(z,x):M(z,x),E=H.userJobsPath(`${z}.ts`);try{return await L(E,I),A.success(`Created job: ${E}`),!0}catch(K){return A.error(`Failed to create job: ${K.message}`),!1}}function M(v,x){let y=x.queue??"default",z=x.tries??3,D=x.backoff??3;return`import { Job } from '@stacksjs/queue'
|
|
3
|
-
|
|
4
|
-
export default new Job({
|
|
5
|
-
/**
|
|
6
|
-
* The job name (optional, defaults to filename)
|
|
7
|
-
*/
|
|
8
|
-
name: '${v}',
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A description of what this job does (optional)
|
|
12
|
-
*/
|
|
13
|
-
description: '${v} job',
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The queue this job should be dispatched to
|
|
17
|
-
*/
|
|
18
|
-
queue: '${y}',
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Number of times to retry if the job fails
|
|
22
|
-
*/
|
|
23
|
-
tries: ${z},
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Seconds to wait between retry attempts
|
|
27
|
-
*/
|
|
28
|
-
backoff: ${D},
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Cron expression for scheduled jobs (optional)
|
|
32
|
-
* Examples:
|
|
33
|
-
* - '* * * * *' - Every minute
|
|
34
|
-
* - '0 * * * *' - Every hour
|
|
35
|
-
* - '0 0 * * *' - Every day at midnight
|
|
36
|
-
*/
|
|
37
|
-
// rate: '* * * * *',
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Backoff configuration for advanced retry strategies (optional)
|
|
41
|
-
*/
|
|
42
|
-
// backoffConfig: {
|
|
43
|
-
// strategy: 'exponential', // 'fixed' | 'exponential' | 'linear'
|
|
44
|
-
// initialDelay: 1000,
|
|
45
|
-
// factor: 2,
|
|
46
|
-
// maxDelay: 60000,
|
|
47
|
-
// },
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Handle the job
|
|
51
|
-
* @param payload - The job payload data
|
|
52
|
-
* @returns The result of the job processing
|
|
53
|
-
*/
|
|
54
|
-
async handle(payload: Record<string, unknown>) {
|
|
55
|
-
// Add your job logic here.
|
|
56
|
-
console.log('Processing job with payload:', payload)
|
|
57
|
-
|
|
58
|
-
return { success: true }
|
|
59
|
-
},
|
|
60
|
-
})
|
|
61
|
-
`}function Q(v,x){let y=x.queue??"default",z=x.tries??3;return`import { log } from '@stacksjs/logging'
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* ${v}
|
|
65
|
-
*
|
|
66
|
-
* Generated job class.
|
|
67
|
-
*/
|
|
68
|
-
export default class ${v} {
|
|
69
|
-
/**
|
|
70
|
-
* Job configuration
|
|
71
|
-
*/
|
|
72
|
-
public static config = {
|
|
73
|
-
/**
|
|
74
|
-
* The queue this job should be dispatched to
|
|
75
|
-
*/
|
|
76
|
-
queue: '${y}',
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Cron expression for scheduled jobs (optional)
|
|
80
|
-
* Examples:
|
|
81
|
-
* - '* * * * *' - Every minute
|
|
82
|
-
* - '0 * * * *' - Every hour
|
|
83
|
-
* - '0 0 * * *' - Every day at midnight
|
|
84
|
-
*/
|
|
85
|
-
// schedule: '0 0 * * *',
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Prevent overlapping job executions
|
|
89
|
-
*/
|
|
90
|
-
withoutOverlapping: false,
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Timeout in seconds
|
|
94
|
-
*/
|
|
95
|
-
timeout: 60,
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Number of retry attempts
|
|
99
|
-
*/
|
|
100
|
-
retries: ${z},
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Delay between retries in seconds
|
|
104
|
-
*/
|
|
105
|
-
retryAfter: [60, 120, 300],
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Execute the job
|
|
110
|
-
* @param payload - The job payload data
|
|
111
|
-
*/
|
|
112
|
-
public static async handle(payload?: Record<string, unknown>): Promise<{ success: boolean }> {
|
|
113
|
-
try {
|
|
114
|
-
log.info('${v}: Starting job execution')
|
|
115
|
-
|
|
116
|
-
// Add your job logic here.
|
|
117
|
-
console.log('Processing with payload:', payload)
|
|
118
|
-
|
|
119
|
-
log.info('${v}: Job completed successfully')
|
|
120
|
-
|
|
121
|
-
return { success: true }
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
log.error('${v}: Job failed:', error)
|
|
125
|
-
throw error
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
`}
|
|
130
|
-
export{T as ka};
|
package/dist/chunk-ay41a7jn.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{projectPath as G,storagePath as J}from"@stacksjs/path";async function L(){let x={generated_at:new Date().toISOString(),packages:{}},E=new Set;try{let z=(await Bun.file(G("package.json")).json())?.stacks?.["dont-discover"];if(Array.isArray(z))for(let A of z)E.add(A)}catch{}let H=G("pantry"),I=["*/package.json","@*/*/package.json"];for(let q of I){let z=new Bun.Glob(q);for await(let A of z.scan({cwd:H,absolute:!0,onlyFiles:!0}))try{let B=await Bun.file(A).json(),C=B?.name;if(!C||!B.stacks||E.has(C))continue;x.packages[C]=B.stacks}catch{}}let F=J("framework/discovered-packages.json");try{let q=await Bun.file(F).json();if(JSON.stringify(q.packages??{})===JSON.stringify(x.packages))return q}catch{}return await Bun.write(F,JSON.stringify(x,null,2)),x}
|
|
3
|
-
export{L as sa};
|
package/dist/chunk-e87s6b8r.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{log as B}from"@stacksjs/logging";import*as G from"@stacksjs/path";import{get as O,writeFile as H}from"@stacksjs/storage";async function V(y){let z=y.name;if(!z)return B.error("Command name is required"),!1;let q=S(z),A=Q(q,y),D=G.commandsPath(`${q}.ts`);try{if(await H(D,A),B.success(`Created command: ${D}`),y.register!==!1)await R(q,y.signature||I(z));return!0}catch(E){return B.error(`Failed to create command: ${E.message}`),!1}}function Q(y,z){let q=z.signature||I(y),A=z.description||`The ${q} command`;return`import type { CLI } from '@stacksjs/types'
|
|
3
|
-
import { log } from '@stacksjs/cli'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ${y} Command
|
|
7
|
-
*
|
|
8
|
-
* ${A}
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
interface ${y}Options {
|
|
12
|
-
verbose: boolean
|
|
13
|
-
// Add your command options here
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default function (cli: CLI) {
|
|
17
|
-
cli
|
|
18
|
-
.command('${q}', '${A}')
|
|
19
|
-
.option('--verbose', 'Enable verbose output', { default: false })
|
|
20
|
-
// Add more options here
|
|
21
|
-
// .option('-n, --name <name>', 'Your name')
|
|
22
|
-
.action(async (options: ${y}Options) => {
|
|
23
|
-
try {
|
|
24
|
-
if (options.verbose) {
|
|
25
|
-
log.info('Running ${q} command...')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
log.info('No command logic implemented yet. Update this command action to add behavior.')
|
|
29
|
-
|
|
30
|
-
log.success('${q} completed successfully!')
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
log.error('${q} failed:', error)
|
|
34
|
-
throw error
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Handle unknown subcommands
|
|
39
|
-
cli.on('${q}:*', () => {
|
|
40
|
-
log.error('Invalid command: %s\\nSee --help for a list of available commands.', cli.args.join(' '))
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
`}async function R(y,z){let q=G.appPath("Commands.ts");try{let A=await O(q),D=A.match(/export default \{([\s\S]*)\} satisfies/);if(D){let E=D[1]??"";if(E.includes(`'${z}'`)){B.info(`Command '${z}' already registered in Commands.ts`);return}let J=` '${z}': '${y}',
|
|
44
|
-
`,L=`${E.trimEnd()}
|
|
45
|
-
${J}`;A=A.replace(/export default \{[\s\S]*\} satisfies/,`export default {${L}} satisfies`),await H(q,A),B.success(`Registered command '${z}' in Commands.ts`)}}catch(A){B.warn(`Could not register command in Commands.ts: ${A.message}`),B.info("You may need to manually add it to app/Commands.ts")}}function S(y){return y.replace(/[-_](.)/g,(z,q)=>q.toUpperCase()).replace(/^(.)/,(z,q)=>q.toUpperCase())}function I(y){return y.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase()}
|
|
46
|
-
export{V as ja};
|
package/dist/chunk-g6k41p49.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// @bun
|
package/dist/chunk-gcjrdkq7.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{qb as O}from"./chunk-v0hqskdk.js";import{log as B}from"@stacksjs/logging";import*as J from"@stacksjs/path";import{doesExist as Q,get as R,writeFile as L}from"@stacksjs/storage";async function X(q){let b=q.name;if(!b)return B.error("Policy name is required"),!1;let z=b.endsWith("Policy")?b:`${b}Policy`,v=q.model||z.replace("Policy",""),I=T(z,v),H=J.appPath(`Policies/${z}.ts`);try{let G=J.appPath("Policies");if(!Q(G)){let{mkdirSync:K}=await import("@stacksjs/storage");K(G,{recursive:!0})}if(await L(H,I),B.success(`Created policy: ${H}`),q.register!==!1)await U(v,z);return!0}catch(G){return B.error(`Failed to create policy: ${G.message}`),!1}}function T(q,b){return`import type _User from '../models/User'
|
|
3
|
-
import { BasePolicy } from '@stacksjs/auth'
|
|
4
|
-
|
|
5
|
-
type UserModel = _User
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ${q}
|
|
9
|
-
*
|
|
10
|
-
* This policy controls authorization for ${b} model actions.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* 1. Register in app/Gates.ts:
|
|
14
|
-
* policies: { '${b}': '${q}' }
|
|
15
|
-
*
|
|
16
|
-
* 2. Use in your code:
|
|
17
|
-
* import { Gate } from '@stacksjs/auth'
|
|
18
|
-
* await Gate.authorize('view', user, ${b.toLowerCase()})
|
|
19
|
-
*
|
|
20
|
-
* 3. Or use the middleware:
|
|
21
|
-
* route.put('/${b.toLowerCase()}s/:${b.toLowerCase()}', 'Update${b}')
|
|
22
|
-
* .middleware('can:update,${b.toLowerCase()}')
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
// TODO: Import or define your ${b} type
|
|
26
|
-
interface ${b} {
|
|
27
|
-
id: number
|
|
28
|
-
user_id: number
|
|
29
|
-
// Add your model properties here
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default class ${q} extends BasePolicy<${b}> {
|
|
33
|
-
/**
|
|
34
|
-
* Run before any other checks.
|
|
35
|
-
* Return true to allow, false to deny, null to continue.
|
|
36
|
-
*/
|
|
37
|
-
before(user: UserModel | null, ability: string): boolean | null {
|
|
38
|
-
// Example: Admins can do anything
|
|
39
|
-
// if (user?.role === 'admin') return true
|
|
40
|
-
return null
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Determine if the user can view any ${b.toLowerCase()}s.
|
|
45
|
-
*/
|
|
46
|
-
viewAny(user: UserModel | null): boolean {
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Determine if the user can view the ${b.toLowerCase()}.
|
|
52
|
-
*/
|
|
53
|
-
view(user: UserModel | null, model: ${b}): boolean {
|
|
54
|
-
return true
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Determine if the user can create ${b.toLowerCase()}s.
|
|
59
|
-
*/
|
|
60
|
-
create(user: UserModel | null): boolean {
|
|
61
|
-
return user !== null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Determine if the user can update the ${b.toLowerCase()}.
|
|
66
|
-
*/
|
|
67
|
-
update(user: UserModel | null, model: ${b}): boolean {
|
|
68
|
-
return user?.id === model.user_id
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Determine if the user can delete the ${b.toLowerCase()}.
|
|
73
|
-
*/
|
|
74
|
-
delete(user: UserModel | null, model: ${b}): boolean {
|
|
75
|
-
return user?.id === model.user_id
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Determine if the user can restore the ${b.toLowerCase()}.
|
|
80
|
-
*/
|
|
81
|
-
restore(user: UserModel | null, model: ${b}): boolean {
|
|
82
|
-
return user?.id === model.user_id
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Determine if the user can permanently delete the ${b.toLowerCase()}.
|
|
87
|
-
*/
|
|
88
|
-
forceDelete(user: UserModel | null, model: ${b}): boolean {
|
|
89
|
-
return user?.id === model.user_id
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
`}async function U(q,b){let z=J.appPath("Gates.ts");try{let v=await R(z),I=v.match(/export const policies[^{]*\{([^}]*)\}/);if(I){let H=I[1]??"";if(H.includes(`'${q}'`)){B.info(`Policy for '${q}' already registered in Gates.ts`);return}let G=` '${q}': '${b}',
|
|
93
|
-
`,K=`${H.trimEnd()}
|
|
94
|
-
${G}`;v=v.replace(/export const policies[^{]*\{([^}]*)\}/,`export const policies: Record<string, string | { policy: string, model?: string }> = {${K}}`),await L(z,v),B.success(`Registered policy '${b}' for '${q}' in Gates.ts`)}}catch(v){B.warn(`Could not register policy in Gates.ts: ${v.message}`),B.info("You may need to manually add it to app/Gates.ts")}}
|
|
95
|
-
export{X as D};
|
package/dist/chunk-h63c1v89.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{NpmScript as i}from"@stacksjs/enums";import{log as t}from"@stacksjs/logging";import{projectPath as m}from"@stacksjs/path";import{runNpmScript as r}from"@stacksjs/utils";async function n(o){t.info("Committing..."),await r(i.Commit,{cwd:m(),...o}),t.success("Committed")}async function a(o){return await n(o)}
|
|
3
|
-
export{n as Pa,a as Qa};
|
package/dist/chunk-n057zfgw.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{qb as G}from"./chunk-v0hqskdk.js";import{log as x}from"@stacksjs/logging";import*as z from"@stacksjs/path";import{doesExist as H,writeFile as I}from"@stacksjs/storage";async function O(q){let j=q.name;if(!j)return x.error("Resource name is required"),!1;let v=j.endsWith("Resource")?j:`${j}Resource`,A=q.model||v.replace("Resource",""),F=q.collection?K(v,A):J(v,A),B=z.appPath("Resources");if(!H(B)){let{mkdirSync:w}=await import("@stacksjs/storage");w(B,{recursive:!0})}let E=z.appPath(`Resources/${v}.ts`);try{return await I(E,F),x.success(`Created resource: ${E}`),!0}catch(w){return x.error(`Failed to create resource: ${w.message}`),!1}}function J(q,j){return`import type { Request } from '@stacksjs/router'
|
|
3
|
-
import { JsonResource } from '@stacksjs/api'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ${q}
|
|
7
|
-
*
|
|
8
|
-
* Transforms ${j} model data for API responses.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* // Single resource
|
|
12
|
-
* return new ${q}(${j.toLowerCase()}).toResponse()
|
|
13
|
-
*
|
|
14
|
-
* // Collection
|
|
15
|
-
* return ${q}.collection(${j.toLowerCase()}s).toResponse()
|
|
16
|
-
*
|
|
17
|
-
* // With additional data
|
|
18
|
-
* return new ${q}(${j.toLowerCase()})
|
|
19
|
-
* .withAdditional({ message: 'Success' })
|
|
20
|
-
* .toResponse()
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
// TODO: Import or define your ${j} type
|
|
24
|
-
interface ${j} {
|
|
25
|
-
id: number
|
|
26
|
-
name: string
|
|
27
|
-
created_at: Date
|
|
28
|
-
updated_at: Date
|
|
29
|
-
// Add your model properties here
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default class ${q} extends JsonResource<${j}> {
|
|
33
|
-
/**
|
|
34
|
-
* Transform the resource into an array.
|
|
35
|
-
*/
|
|
36
|
-
toArray(request?: Request): Record<string, any> {
|
|
37
|
-
return {
|
|
38
|
-
id: this.resource.id,
|
|
39
|
-
name: this.resource.name,
|
|
40
|
-
|
|
41
|
-
// Conditional fields
|
|
42
|
-
// secret: this.when(request?.user?.isAdmin, this.resource.secret),
|
|
43
|
-
|
|
44
|
-
// Loaded relationships
|
|
45
|
-
// posts: this.whenLoaded('posts', () =>
|
|
46
|
-
// PostResource.collection(this.resource.posts)
|
|
47
|
-
// ),
|
|
48
|
-
|
|
49
|
-
// Relationship counts
|
|
50
|
-
// posts_count: this.whenCounted('posts'),
|
|
51
|
-
|
|
52
|
-
// Timestamps
|
|
53
|
-
created_at: this.resource.created_at,
|
|
54
|
-
updated_at: this.resource.updated_at,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`}function K(q,j){let v=q.replace("Collection","");return`import type { Request } from '@stacksjs/router'
|
|
59
|
-
import { JsonResource, ResourceCollection } from '@stacksjs/api'
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* ${q}
|
|
63
|
-
*
|
|
64
|
-
* Collection resource for ${j} with custom collection behavior.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* return new ${q}(${j.toLowerCase()}s).toResponse()
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
// TODO: Import or define your ${j} type
|
|
71
|
-
interface ${j} {
|
|
72
|
-
id: number
|
|
73
|
-
name: string
|
|
74
|
-
created_at: Date
|
|
75
|
-
updated_at: Date
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Individual resource for the collection
|
|
80
|
-
*/
|
|
81
|
-
class ${v} extends JsonResource<${j}> {
|
|
82
|
-
toArray(request?: Request): Record<string, any> {
|
|
83
|
-
return {
|
|
84
|
-
id: this.resource.id,
|
|
85
|
-
name: this.resource.name,
|
|
86
|
-
created_at: this.resource.created_at,
|
|
87
|
-
updated_at: this.resource.updated_at,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Collection resource with custom behavior
|
|
94
|
-
*/
|
|
95
|
-
export default class ${q} extends ResourceCollection<${j}, ${v}> {
|
|
96
|
-
constructor(resources: ${j}[]) {
|
|
97
|
-
super(resources, ${v})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Add collection-level data to the response
|
|
102
|
-
*/
|
|
103
|
-
toResponse(request?: Request): Record<string, any> {
|
|
104
|
-
return {
|
|
105
|
-
...super.toResponse(request),
|
|
106
|
-
meta: {
|
|
107
|
-
total: this.count(),
|
|
108
|
-
// Add any collection-level metadata here
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
`}
|
|
114
|
-
export{O as E};
|
package/dist/chunk-v0hqskdk.js
DELETED
package/dist/chunk-vv4nqhgg.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{installPackage as t}from"@stacksjs/cli";async function o(a){if(a?.table)await n();if(a?.calendar)await s()}async function r(a){return await o(a)}async function n(){await t("@stacksjs/table")}async function s(){await t("@stacksjs/calendar")}async function d(a){for(let i of a)await t(i)}
|
|
3
|
-
export{o as kb,r as lb,n as mb,s as nb,d as ob};
|
package/dist/chunk-x0cnhg3z.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{G as x}from"./chunk-heh4x32p.js";import{italic as I}from"@stacksjs/cli";import{log as W}from"@stacksjs/logging";import{path as Z}from"@stacksjs/path";import{writeTextFile as L}from"@stacksjs/storage";var P={str:"string",string:"string",varchar:"string",text:"text",longtext:"text",int:"number",integer:"number",number:"number",num:"number",bool:"boolean",boolean:"boolean",date:"date",datetime:"date",json:"json"};function U(G){if(!G)return[];let H=G.split(",").map((q)=>q.trim()).filter(Boolean),J=[];for(let q of H){let[K,O="string"]=q.split(":"),Q=K?.trim();if(!Q)continue;let B=P[O.trim().toLowerCase()]??"string";J.push({name:Q,type:B})}return J}function V(G){if(!G)return G;let H=G.toLowerCase();if(H.endsWith("s")||H.endsWith("x")||H.endsWith("z")||H.endsWith("ch")||H.endsWith("sh"))return`${G}es`;if(H.endsWith("y")&&!/[aeiou]y$/.test(H))return`${G.slice(0,-1)}ies`;return`${G}s`}function v(G){return G.replace(/(^|[-_\s])(\w)/g,(H,J,q)=>String(q).toUpperCase())}function X(G){return G.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()}function Y(G){if(G.length===0)return" title: { type: 'string', fillable: true, validation: { rule: schema.string().required() } },";return G.map((H)=>{let J=H.type,q=J==="number"?"schema.number()":J==="boolean"?"schema.boolean()":J==="date"?"schema.date()":J==="json"?"schema.object({})":"schema.string()",K=J==="number"?"number":J==="boolean"?"boolean":J==="date"?"date":J==="json"?"json":"string";return` ${H.name}: { type: '${K}', fillable: true, validation: { rule: ${q} } },`}).join(`
|
|
3
|
-
`)}function _(G){if(G.length===0)return" .addColumn('title', 'varchar(255)', col => col.notNull())";return G.map((H)=>{switch(H.type){case"number":return` .addColumn('${H.name}', 'integer')`;case"boolean":return` .addColumn('${H.name}', 'boolean', col => col.defaultTo(false))`;case"text":return` .addColumn('${H.name}', 'text')`;case"date":return` .addColumn('${H.name}', 'timestamp')`;case"json":return` .addColumn('${H.name}', 'text')`;default:return` .addColumn('${H.name}', 'varchar(255)')`}}).join(`
|
|
4
|
-
`)}function D(G,H,J){let q=v(G);switch(H){case"Index":return`import { Action } from '@stacksjs/actions'
|
|
5
|
-
import ${q} from '~/app/Models/${q}'
|
|
6
|
-
|
|
7
|
-
export default new Action({
|
|
8
|
-
name: '${q}IndexAction',
|
|
9
|
-
description: 'List ${V(q)}',
|
|
10
|
-
|
|
11
|
-
async handle() {
|
|
12
|
-
return await ${q}.all()
|
|
13
|
-
},
|
|
14
|
-
})`;case"Show":return`import { Action } from '@stacksjs/actions'
|
|
15
|
-
import ${q} from '~/app/Models/${q}'
|
|
16
|
-
|
|
17
|
-
export default new Action({
|
|
18
|
-
name: '${q}ShowAction',
|
|
19
|
-
description: 'Show a single ${q}',
|
|
20
|
-
|
|
21
|
-
async handle(request) {
|
|
22
|
-
const id = Number(request.get('id'))
|
|
23
|
-
return await ${q}.findOrFail(id)
|
|
24
|
-
},
|
|
25
|
-
})`;case"Store":{let K=(J.length>0?J:[{name:"title",type:"string"}]).map((O)=>`'${O.name}'`).join(", ");return`import { Action } from '@stacksjs/actions'
|
|
26
|
-
import ${q} from '~/app/Models/${q}'
|
|
27
|
-
|
|
28
|
-
export default new Action({
|
|
29
|
-
name: '${q}StoreAction',
|
|
30
|
-
description: 'Create a new ${q}',
|
|
31
|
-
|
|
32
|
-
async handle(request) {
|
|
33
|
-
const data = request.only([${K}])
|
|
34
|
-
return await ${q}.create(data)
|
|
35
|
-
},
|
|
36
|
-
})`}case"Update":{let K=(J.length>0?J:[{name:"title",type:"string"}]).map((O)=>`'${O.name}'`).join(", ");return`import { Action } from '@stacksjs/actions'
|
|
37
|
-
import ${q} from '~/app/Models/${q}'
|
|
38
|
-
|
|
39
|
-
export default new Action({
|
|
40
|
-
name: '${q}UpdateAction',
|
|
41
|
-
description: 'Update an existing ${q}',
|
|
42
|
-
|
|
43
|
-
async handle(request) {
|
|
44
|
-
const id = Number(request.get('id'))
|
|
45
|
-
const data = request.only([${K}])
|
|
46
|
-
return await ${q}.update(id, data)
|
|
47
|
-
},
|
|
48
|
-
})`}case"Destroy":return`import { Action } from '@stacksjs/actions'
|
|
49
|
-
import ${q} from '~/app/Models/${q}'
|
|
50
|
-
|
|
51
|
-
export default new Action({
|
|
52
|
-
name: '${q}DestroyAction',
|
|
53
|
-
description: 'Delete a ${q}',
|
|
54
|
-
|
|
55
|
-
async handle(request) {
|
|
56
|
-
const id = Number(request.get('id'))
|
|
57
|
-
const deleted = await ${q}.delete(id)
|
|
58
|
-
return { deleted }
|
|
59
|
-
},
|
|
60
|
-
})`}}function E(G,H){return`import { defineModel } from '@stacksjs/orm'
|
|
61
|
-
import { schema } from '@stacksjs/validation'
|
|
62
|
-
|
|
63
|
-
export default defineModel({
|
|
64
|
-
name: '${v(G)}',
|
|
65
|
-
table: '${V(X(G))}',
|
|
66
|
-
attributes: {
|
|
67
|
-
${Y(H)}
|
|
68
|
-
},
|
|
69
|
-
traits: { useTimestamps: true, useUuid: false },
|
|
70
|
-
} as const)
|
|
71
|
-
`}function N(G,H){return`import type { Database } from '@stacksjs/database'
|
|
72
|
-
import { sql } from '@stacksjs/database'
|
|
73
|
-
|
|
74
|
-
export async function up(db: Database<any>) {
|
|
75
|
-
await db.schema
|
|
76
|
-
.createTable('${V(X(G))}')
|
|
77
|
-
.addColumn('id', 'serial', col => col.primaryKey())
|
|
78
|
-
${_(H)}
|
|
79
|
-
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
|
|
80
|
-
.addColumn('updated_at', 'timestamp')
|
|
81
|
-
.execute()
|
|
82
|
-
}
|
|
83
|
-
`}async function $(G,H){if(x()){let J=H.split(`
|
|
84
|
-
`);W.info(`[dry-run] would write ${G} (${J.length} lines)`),process.stdout.write(`${J.slice(0,60).map((q)=>` ${q}`).join(`
|
|
85
|
-
`)}
|
|
86
|
-
|
|
87
|
-
`);return}await L({path:G,data:H})}async function h(G,H){let J=v(G);if(!J)throw Error("scaffold:crud requires a non-empty resource name");let q=U(H.fields);W.info(`Scaffolding CRUD for ${I(J)} (${q.length||"no"} fields)`),await $(Z.userModelsPath(`${J}.ts`),E(J,q));let O=`${Date.now().toString()}-create-${V(X(G))}-table.ts`;await $(Z.userMigrationsPath(O),N(G,q));for(let Q of["Index","Show","Store","Update","Destroy"])await $(Z.userActionsPath(`${J}${Q}Action.ts`),D(G,Q,q));W.success(`CRUD scaffold complete: model + migration + 5 actions for ${J}`),W.info(`Next: register \`route.resource('${V(X(G))}', '${J}')\` in routes/api.ts`)}
|
|
88
|
-
export{U as B,h as C};
|