core-nails 1.0.5 → 1.0.6

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.
@@ -34,15 +34,8 @@ export default ${modelName};
34
34
  fs.mkdirSync(dbDir, { recursive: true });
35
35
  const schemaFilePath = path.join(dbDir, "schema.ts");
36
36
  const schemaBaseContent = `import FirebaseAdmin from "@lib/FirebaseAdmin";
37
- import { z } from "zod";
38
-
39
- // Helper Function
40
- const FirebaseTimestamp = z.union([
41
- z.instanceof(FirebaseAdmin.firestore.Timestamp),
42
- z.date(),
43
- z.custom((val) => val === FirebaseAdmin.firestore.FieldValue.serverTimestamp(), { message: "Expected serverTimestamp()" }),
44
- ]);
45
- `;
37
+ import Nails from "core-nails";
38
+ import { z } from "zod";`;
46
39
  // Ensure schema file exists
47
40
  if (!fs.existsSync(schemaFilePath)) {
48
41
  fs.writeFileSync(schemaFilePath, schemaBaseContent);
@@ -54,8 +47,8 @@ const FirebaseTimestamp = z.union([
54
47
  const schemaStub = `
55
48
  // ${modelName} Schema
56
49
  export const ${modelName}Schema = z.object({
57
- createdAt: FirebaseTimestamp.optional(),
58
- updatedAt: FirebaseTimestamp.optional(),
50
+ createdAt: Nails.FirebaseTimestampType(FirebaseAdmin).optional(),
51
+ updatedAt: Nails.FirebaseTimestampType(FirebaseAdmin).optional(),
59
52
  });
60
53
  export type ${modelName}Type = z.infer<typeof ${modelName}Schema>;
61
54
  `;
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ declare function FirebaseTimestampType(FirebaseAdmin: any): z.ZodUnion<readonly [z.ZodCustom<any, any>, z.ZodDate, z.ZodCustom<unknown, unknown>]>;
3
+ export default FirebaseTimestampType;
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+ function FirebaseTimestampType(FirebaseAdmin) {
3
+ return z.union([
4
+ z.instanceof(FirebaseAdmin.firestore.Timestamp),
5
+ z.date(),
6
+ z.custom((val) => val === FirebaseAdmin.firestore.FieldValue.serverTimestamp(), { message: "Expected serverTimestamp()" }),
7
+ ]);
8
+ }
9
+ export default FirebaseTimestampType;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import InitializeModel from "./helpers/InitializeModel.js";
2
+ import FirebaseTimestampType from "./helpers/FirebaseTimestampType.js";
2
3
  declare const _default: {
3
4
  InitializeModel: typeof InitializeModel;
5
+ FirebaseTimestampType: typeof FirebaseTimestampType;
4
6
  };
5
7
  export default _default;
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import InitializeModel from "./helpers/InitializeModel.js";
2
- export default { InitializeModel };
2
+ import FirebaseTimestampType from "./helpers/FirebaseTimestampType.js";
3
+ export default { InitializeModel, FirebaseTimestampType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-nails",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "scripts": {
5
5
  "build": "tsc"
6
6
  },
@@ -44,15 +44,8 @@ export default ${modelName};
44
44
  const schemaFilePath = path.join(dbDir, "schema.ts");
45
45
 
46
46
  const schemaBaseContent = `import FirebaseAdmin from "@lib/FirebaseAdmin";
47
- import { z } from "zod";
48
-
49
- // Helper Function
50
- const FirebaseTimestamp = z.union([
51
- z.instanceof(FirebaseAdmin.firestore.Timestamp),
52
- z.date(),
53
- z.custom((val) => val === FirebaseAdmin.firestore.FieldValue.serverTimestamp(), { message: "Expected serverTimestamp()" }),
54
- ]);
55
- `;
47
+ import Nails from "core-nails";
48
+ import { z } from "zod";`;
56
49
 
57
50
  // Ensure schema file exists
58
51
  if (!fs.existsSync(schemaFilePath)) {
@@ -65,8 +58,8 @@ const FirebaseTimestamp = z.union([
65
58
  const schemaStub = `
66
59
  // ${modelName} Schema
67
60
  export const ${modelName}Schema = z.object({
68
- createdAt: FirebaseTimestamp.optional(),
69
- updatedAt: FirebaseTimestamp.optional(),
61
+ createdAt: Nails.FirebaseTimestampType(FirebaseAdmin).optional(),
62
+ updatedAt: Nails.FirebaseTimestampType(FirebaseAdmin).optional(),
70
63
  });
71
64
  export type ${modelName}Type = z.infer<typeof ${modelName}Schema>;
72
65
  `;
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+
3
+ function FirebaseTimestampType(FirebaseAdmin: any) {
4
+ return z.union([
5
+ z.instanceof(FirebaseAdmin.firestore.Timestamp),
6
+ z.date(),
7
+ z.custom((val) => val === FirebaseAdmin.firestore.FieldValue.serverTimestamp(), { message: "Expected serverTimestamp()" }),
8
+ ]);
9
+ }
10
+
11
+ export default FirebaseTimestampType;
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import InitializeModel from "./helpers/InitializeModel.js";
2
+ import FirebaseTimestampType from "./helpers/FirebaseTimestampType.js";
2
3
 
3
- export default { InitializeModel };
4
+ export default { InitializeModel, FirebaseTimestampType };