@karmaniverous/smoz 0.2.2 → 0.2.4

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.
@@ -73,111 +73,111 @@ const getParamName = (s) => {
73
73
  const toDirSeg = (s) => isParamSeg(s) ? `[${getParamName(s)}]` : s;
74
74
  /** Normalize a segment for API paths (Serverless/OpenAPI‑native). */
75
75
  const toPathSeg = (s) => isParamSeg(s) ? `{${getParamName(s)}}` : s;
76
- const lambdaHttpTemplate = ({ token, basePath, method, }) => `/**
77
- * Registration: ${method.toUpperCase()} /${basePath} (public)
78
- */
79
- import { join } from 'node:path';
80
-
81
- import { z } from 'zod';
82
-
83
- import { app, APP_ROOT_ABS } from '@/app/config/app.config';
84
-
85
- export const eventSchema = z.any();
86
- export const responseSchema = z.any();
87
-
88
- export const fn = app.defineFunction({
89
- eventType: '${token}',
90
- httpContexts: ['public'],
91
- method: '${method}',
92
- basePath: '${basePath}',
93
- contentType: 'application/json',
94
- eventSchema,
95
- responseSchema,
96
- callerModuleUrl: import.meta.url,
97
- endpointsRootAbs: join(APP_ROOT_ABS, 'functions', '${token}').replace(/\\\\\\\\/g, '/'),
98
- });
76
+ const lambdaHttpTemplate = ({ token, basePath, method, }) => `/**
77
+ * Registration: ${method.toUpperCase()} /${basePath} (public)
78
+ */
79
+ import { join } from 'node:path';
80
+
81
+ import { z } from 'zod';
82
+
83
+ import { app, APP_ROOT_ABS } from '@/app/config/app.config';
84
+
85
+ export const eventSchema = z.any();
86
+ export const responseSchema = z.any();
87
+
88
+ export const fn = app.defineFunction({
89
+ eventType: '${token}',
90
+ httpContexts: ['public'],
91
+ method: '${method}',
92
+ basePath: '${basePath}',
93
+ contentType: 'application/json',
94
+ eventSchema,
95
+ responseSchema,
96
+ callerModuleUrl: import.meta.url,
97
+ endpointsRootAbs: join(APP_ROOT_ABS, 'functions', '${token}').replace(/\\\\\\\\/g, '/'),
98
+ });
99
99
  `;
100
- const handlerHttpTemplate = () => `/**
101
- * Handler: replace with your business logic.
102
- */
103
- import { z } from 'zod';
104
-
105
- import type { responseSchema } from './lambda';
106
- import { fn } from './lambda';
107
-
108
- type Response = z.infer<typeof responseSchema>;
109
-
110
- export const handler = fn.handler(async (): Promise<Response> => {
111
- return {} as Response;
112
- });
100
+ const handlerHttpTemplate = () => `/**
101
+ * Handler: replace with your business logic.
102
+ */
103
+ import { z } from 'zod';
104
+
105
+ import type { responseSchema } from './lambda';
106
+ import { fn } from './lambda';
107
+
108
+ type Response = z.infer<typeof responseSchema>;
109
+
110
+ export const handler = fn.handler(async (): Promise<Response> => {
111
+ return {} as Response;
112
+ });
113
113
  `;
114
114
  const openapiTemplate = ({ params, pathTemplate, }) => {
115
115
  const paramsBlock = params.length > 0
116
- ? ` parameters: [
116
+ ? ` parameters: [
117
117
  ${params
118
118
  .map((p) => ` { name: '${p}', in: 'path', required: true, schema: { type: 'string' }, description: 'Path parameter: ${p}' },`)
119
- .join('\n')}
120
- ],
119
+ .join('\n')}
120
+ ],
121
121
  `
122
122
  : '';
123
- return `/* REQUIREMENTS
124
- - Define OpenAPI Path Item for the new endpoint.
125
- */
126
- import { eventSchema, fn, responseSchema } from './lambda';
127
-
128
- fn.openapi({
129
- summary: 'Describe your endpoint',
130
- description: 'Describe your endpoint. Path template: ${pathTemplate}.',
131
- ${paramsBlock} requestBody: {
132
- description: 'Request payload.',
133
- content: { 'application/json': { schema: eventSchema } },
134
- },
135
- responses: {
136
- 200: {
137
- description: 'Ok',
138
- content: { 'application/json': { schema: responseSchema } },
139
- },
140
- },
141
- tags: [],
142
- });
143
-
144
- export {};
123
+ return `/* REQUIREMENTS
124
+ - Define OpenAPI Path Item for the new endpoint.
125
+ */
126
+ import { eventSchema, fn, responseSchema } from './lambda';
127
+
128
+ fn.openapi({
129
+ summary: 'Describe your endpoint',
130
+ description: 'Describe your endpoint. Path template: ${pathTemplate}.',
131
+ ${paramsBlock} requestBody: {
132
+ description: 'Request payload.',
133
+ content: { 'application/json': { schema: eventSchema } },
134
+ },
135
+ responses: {
136
+ 200: {
137
+ description: 'Ok',
138
+ content: { 'application/json': { schema: responseSchema } },
139
+ },
140
+ },
141
+ tags: [],
142
+ });
143
+
144
+ export {};
145
145
  `;
146
146
  };
147
- const lambdaInternalTemplate = (token) => `/**
148
- * Registration: internal ${token} function.
149
- */
150
- import { join } from 'node:path';
151
-
152
- import { z } from 'zod';
153
-
154
- import { app, APP_ROOT_ABS } from '@/app/config/app.config';
155
-
156
- export const eventSchema = z.any();
157
- export const responseSchema = z.any();
158
-
159
- export const fn = app.defineFunction({
160
- eventType: '${token}',
161
- eventSchema,
162
- responseSchema,
163
- callerModuleUrl: import.meta.url,
164
- endpointsRootAbs: join(APP_ROOT_ABS, 'functions', '${token}').replace(/\\\\\\\\/g, '/'),
165
- });
147
+ const lambdaInternalTemplate = (token) => `/**
148
+ * Registration: internal ${token} function.
149
+ */
150
+ import { join } from 'node:path';
151
+
152
+ import { z } from 'zod';
153
+
154
+ import { app, APP_ROOT_ABS } from '@/app/config/app.config';
155
+
156
+ export const eventSchema = z.any();
157
+ export const responseSchema = z.any();
158
+
159
+ export const fn = app.defineFunction({
160
+ eventType: '${token}',
161
+ eventSchema,
162
+ responseSchema,
163
+ callerModuleUrl: import.meta.url,
164
+ endpointsRootAbs: join(APP_ROOT_ABS, 'functions', '${token}').replace(/\\\\\\\\/g, '/'),
165
+ });
166
166
  `;
167
- const handlerInternalTemplate = () => `/**
168
- * Handler: replace with your business logic.
169
- */
170
- import { z } from 'zod';
171
-
172
- import type { responseSchema } from './lambda';
173
- import { fn } from './lambda';
174
-
175
- type Response = z.infer<typeof responseSchema>;
176
-
177
- export const handler = fn.handler(async (_event): Promise<Response> => {
178
- void _event;
179
- return {} as Response;
180
- });
167
+ const handlerInternalTemplate = () => `/**
168
+ * Handler: replace with your business logic.
169
+ */
170
+ import { z } from 'zod';
171
+
172
+ import type { responseSchema } from './lambda';
173
+ import { fn } from './lambda';
174
+
175
+ type Response = z.infer<typeof responseSchema>;
176
+
177
+ export const handler = fn.handler(async (_event): Promise<Response> => {
178
+ void _event;
179
+ return {} as Response;
180
+ });
181
181
  `;
182
182
  const runAdd = async (root, spec) => {
183
183
  const parts = spec.split('/').filter(Boolean);
@@ -435,7 +435,7 @@ const runOpenapi = async (root, opts) => {
435
435
  */
436
436
  const toPosix$1 = (p) => p.split(path.sep).join('/');
437
437
  const withoutTsExt = (p) => p.endsWith('.ts') ? p.slice(0, -3) : p;
438
- const HEADER = `/* AUTO-GENERATED by smoz register — DO NOT EDIT */
438
+ const HEADER = `/* AUTO-GENERATED by smoz register — DO NOT EDIT */
439
439
  `;
440
440
  const formatMaybe = async (root, filePath, source) => {
441
441
  try {
@@ -1058,8 +1058,15 @@ const excludeDev = (rel) => {
1058
1058
  };
1059
1059
  const excludeTemplate = (rel) => {
1060
1060
  const posixRel = rel.replace(/\\/g, '/');
1061
+ // Do not copy the template's dev tsconfig; downstream apps use
1062
+ // tsconfig.downstream.json (renamed to tsconfig.json) instead.
1061
1063
  if (posixRel === 'tsconfig.json')
1062
- return true; // skip dev tsconfig from template
1064
+ return true;
1065
+ // Do not copy the template's package.json; we always handle the manifest
1066
+ // via an additive merge (create when missing, never overwrite existing keys).
1067
+ // Copying would only trigger a scary/irrelevant conflict prompt.
1068
+ if (posixRel === 'package.json')
1069
+ return true;
1063
1070
  return excludeDev(rel);
1064
1071
  };
1065
1072
  const runInit = async (root, template = 'default', opts) => {