payload-live-preview 1.0.0

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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +389 -0
  3. package/dist/adapters/astro/RichText.astro +55 -0
  4. package/dist/adapters/astro/index.cjs +370 -0
  5. package/dist/adapters/astro/index.cjs.map +1 -0
  6. package/dist/adapters/astro/index.d.cts +105 -0
  7. package/dist/adapters/astro/index.d.ts +105 -0
  8. package/dist/adapters/astro/index.js +364 -0
  9. package/dist/adapters/astro/index.js.map +1 -0
  10. package/dist/adapters/astro/middleware-entry.cjs +303 -0
  11. package/dist/adapters/astro/middleware-entry.cjs.map +1 -0
  12. package/dist/adapters/astro/middleware-entry.d.cts +15 -0
  13. package/dist/adapters/astro/middleware-entry.d.ts +15 -0
  14. package/dist/adapters/astro/middleware-entry.js +297 -0
  15. package/dist/adapters/astro/middleware-entry.js.map +1 -0
  16. package/dist/adapters/nextjs/index.cjs +309 -0
  17. package/dist/adapters/nextjs/index.cjs.map +1 -0
  18. package/dist/adapters/nextjs/index.d.cts +75 -0
  19. package/dist/adapters/nextjs/index.d.ts +75 -0
  20. package/dist/adapters/nextjs/index.js +306 -0
  21. package/dist/adapters/nextjs/index.js.map +1 -0
  22. package/dist/adapters/nuxt/index.cjs +299 -0
  23. package/dist/adapters/nuxt/index.cjs.map +1 -0
  24. package/dist/adapters/nuxt/index.d.cts +126 -0
  25. package/dist/adapters/nuxt/index.d.ts +126 -0
  26. package/dist/adapters/nuxt/index.js +294 -0
  27. package/dist/adapters/nuxt/index.js.map +1 -0
  28. package/dist/adapters/sveltekit/index.cjs +275 -0
  29. package/dist/adapters/sveltekit/index.cjs.map +1 -0
  30. package/dist/adapters/sveltekit/index.d.cts +80 -0
  31. package/dist/adapters/sveltekit/index.d.ts +80 -0
  32. package/dist/adapters/sveltekit/index.js +273 -0
  33. package/dist/adapters/sveltekit/index.js.map +1 -0
  34. package/dist/bind-BSgxoQhN.d.cts +1137 -0
  35. package/dist/bind-BSgxoQhN.d.ts +1137 -0
  36. package/dist/codegen-astro.cjs +612 -0
  37. package/dist/codegen-astro.cjs.map +1 -0
  38. package/dist/codegen-astro.d.cts +54 -0
  39. package/dist/codegen-astro.d.ts +54 -0
  40. package/dist/codegen-astro.js +610 -0
  41. package/dist/codegen-astro.js.map +1 -0
  42. package/dist/codegen-cli.cjs +669 -0
  43. package/dist/codegen-cli.cjs.map +1 -0
  44. package/dist/codegen-cli.d.cts +19 -0
  45. package/dist/codegen-cli.d.ts +19 -0
  46. package/dist/codegen-cli.js +667 -0
  47. package/dist/codegen-cli.js.map +1 -0
  48. package/dist/codegen.cjs +551 -0
  49. package/dist/codegen.cjs.map +1 -0
  50. package/dist/codegen.d.cts +162 -0
  51. package/dist/codegen.d.ts +162 -0
  52. package/dist/codegen.js +547 -0
  53. package/dist/codegen.js.map +1 -0
  54. package/dist/core.cjs +3684 -0
  55. package/dist/core.cjs.map +1 -0
  56. package/dist/core.d.cts +24 -0
  57. package/dist/core.d.ts +24 -0
  58. package/dist/core.js +3657 -0
  59. package/dist/core.js.map +1 -0
  60. package/dist/index.cjs +4083 -0
  61. package/dist/index.cjs.map +1 -0
  62. package/dist/index.d.cts +472 -0
  63. package/dist/index.d.ts +472 -0
  64. package/dist/index.js +4040 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/middleware-BwIlf0jW.d.cts +168 -0
  67. package/dist/middleware-BwIlf0jW.d.ts +168 -0
  68. package/dist/payload.cjs +31 -0
  69. package/dist/payload.cjs.map +1 -0
  70. package/dist/payload.d.cts +87 -0
  71. package/dist/payload.d.ts +87 -0
  72. package/dist/payload.js +29 -0
  73. package/dist/payload.js.map +1 -0
  74. package/dist/preview-request-DAvxm18T.d.cts +68 -0
  75. package/dist/preview-request-DAvxm18T.d.ts +68 -0
  76. package/package.json +186 -0
@@ -0,0 +1,162 @@
1
+ import { Project } from 'ts-morph';
2
+
3
+ /**
4
+ * Internal schema representation used by the codegen pipeline.
5
+ *
6
+ * Decoupled from `PayloadFieldSchema` (the runtime shape that arrives
7
+ * via postMessage) because:
8
+ *
9
+ * 1. Static analysis sees richer information — block definitions,
10
+ * relationship targets, hasMany — that the runtime shape may not
11
+ * always carry.
12
+ * 2. The emit phase wants ergonomic structures (TypeScript-like
13
+ * type references) that the runtime never needs.
14
+ *
15
+ * @module @codegen/parser/types
16
+ */
17
+ interface ExtractedSchema {
18
+ readonly globals: readonly ExtractedSlug[];
19
+ readonly collections: readonly ExtractedSlug[];
20
+ /** Diagnostics produced during extraction. Soft warnings only. */
21
+ readonly diagnostics: readonly string[];
22
+ }
23
+ interface ExtractedSlug {
24
+ /** The Payload slug (`'homepage'`, `'posts'`, …). */
25
+ readonly slug: string;
26
+ /** PascalCase type name (`'Homepage'`, `'Post'`, …). */
27
+ readonly typeName: string;
28
+ /** Fully-resolved field tree. */
29
+ readonly fields: readonly ExtractedField[];
30
+ }
31
+ type ExtractedField = ExtractedScalarField | ExtractedArrayField | ExtractedBlocksField | ExtractedGroupField | ExtractedRelationshipField | ExtractedUploadField | ExtractedJsonField | ExtractedSelectField;
32
+ interface ExtractedFieldBase {
33
+ readonly name: string;
34
+ readonly required: boolean;
35
+ readonly localized: boolean;
36
+ }
37
+ interface ExtractedScalarField extends ExtractedFieldBase {
38
+ readonly kind: 'scalar';
39
+ readonly typeRef: 'string' | 'number' | 'boolean' | 'Date' | 'unknown';
40
+ }
41
+ interface ExtractedArrayField extends ExtractedFieldBase {
42
+ readonly kind: 'array';
43
+ readonly fields: readonly ExtractedField[];
44
+ }
45
+ interface ExtractedBlocksField extends ExtractedFieldBase {
46
+ readonly kind: 'blocks';
47
+ readonly blocks: readonly ExtractedBlock[];
48
+ }
49
+ interface ExtractedBlock {
50
+ readonly slug: string;
51
+ readonly typeName: string;
52
+ readonly fields: readonly ExtractedField[];
53
+ }
54
+ interface ExtractedGroupField extends ExtractedFieldBase {
55
+ readonly kind: 'group';
56
+ readonly fields: readonly ExtractedField[];
57
+ }
58
+ interface ExtractedRelationshipField extends ExtractedFieldBase {
59
+ readonly kind: 'relationship';
60
+ readonly target: string | readonly string[];
61
+ readonly hasMany: boolean;
62
+ }
63
+ interface ExtractedUploadField extends ExtractedFieldBase {
64
+ readonly kind: 'upload';
65
+ readonly target: string;
66
+ }
67
+ interface ExtractedJsonField extends ExtractedFieldBase {
68
+ readonly kind: 'json';
69
+ }
70
+ interface ExtractedSelectField extends ExtractedFieldBase {
71
+ readonly kind: 'select';
72
+ readonly options: readonly string[];
73
+ readonly hasMany: boolean;
74
+ }
75
+
76
+ /**
77
+ * Schema-level extraction: open `payload.config.ts`, find every
78
+ * collection and global definition, walk into them.
79
+ *
80
+ * The extractor is deliberately lenient. Payload configurations are
81
+ * full TypeScript programs — a strict parser would have to model
82
+ * conditional types, factory functions, plugin closures. Instead we
83
+ * recognise the *common* shapes (object literal, identifier
84
+ * referencing an imported literal, default export from a sibling
85
+ * file) and emit a diagnostic for anything we can't unwrap.
86
+ *
87
+ * @module @codegen/parser/extract-schema
88
+ */
89
+
90
+ interface ExtractSchemaOptions {
91
+ /** Absolute or relative path to `payload.config.ts`. */
92
+ readonly configPath: string;
93
+ /** When provided, used instead of constructing a fresh ts-morph project. */
94
+ readonly project?: Project;
95
+ /**
96
+ * Optional path to a `tsconfig.json`. When set, ts-morph loads the
97
+ * project's module-resolution configuration so cross-file imports
98
+ * (Homepage from './globals') can be followed.
99
+ */
100
+ readonly tsConfigFilePath?: string;
101
+ }
102
+ declare function extractSchema(options: ExtractSchemaOptions): ExtractedSchema;
103
+
104
+ /**
105
+ * Render `ExtractedSchema` to a TypeScript source string.
106
+ *
107
+ * The output is one self-contained `.ts` file that ships:
108
+ *
109
+ * - one `interface` per global and per collection,
110
+ * - nested `interface` declarations for `group`/`array`/`blocks`,
111
+ * - discriminated unions for `blocks` fields (one variant per slug),
112
+ * - `PayloadCollections` / `PayloadGlobals` maps for slug-keyed
113
+ * access (`PayloadCollections['posts']`), and
114
+ * - a `PayloadSlug` alias.
115
+ *
116
+ * Nothing in the runtime depends on this output — consumers import
117
+ * what they need by name.
118
+ *
119
+ * @module @codegen/emit/emit-types
120
+ */
121
+
122
+ interface EmitOptions {
123
+ /** When true, includes a `@deprecated` JSDoc on localized fields. */
124
+ readonly markLocalizedAsDeprecated?: boolean;
125
+ /** Header text injected at the top of the output. Defaults sensibly. */
126
+ readonly header?: string;
127
+ }
128
+ declare function emitTypes(schema: ExtractedSchema, options?: EmitOptions): string;
129
+
130
+ /**
131
+ * Programmatic codegen API.
132
+ *
133
+ * ```ts
134
+ * import { generateTypes } from 'payload-live-preview/codegen';
135
+ * const { code, diagnostics } = await generateTypes({
136
+ * configPath: 'backend/src/payload.config.ts',
137
+ * outFile: 'frontend/src/payload-types.ts',
138
+ * });
139
+ * ```
140
+ *
141
+ * @module @codegen
142
+ */
143
+
144
+ interface GenerateTypesOptions extends Pick<ExtractSchemaOptions, 'configPath' | 'project' | 'tsConfigFilePath'>, EmitOptions {
145
+ /**
146
+ * If set, the generated code is written to this absolute or
147
+ * cwd-relative path. The function still returns the rendered string
148
+ * in `code` so callers can verify before writing.
149
+ */
150
+ readonly outFile?: string;
151
+ /** Working directory used to resolve relative paths. Defaults to `process.cwd()`. */
152
+ readonly cwd?: string;
153
+ }
154
+ interface GenerateTypesResult {
155
+ readonly code: string;
156
+ readonly diagnostics: readonly string[];
157
+ readonly schema: ExtractedSchema;
158
+ readonly outFile?: string;
159
+ }
160
+ declare function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult>;
161
+
162
+ export { type ExtractedField, type ExtractedSchema, type ExtractedSlug, type GenerateTypesOptions, type GenerateTypesResult, emitTypes, extractSchema, generateTypes };
@@ -0,0 +1,162 @@
1
+ import { Project } from 'ts-morph';
2
+
3
+ /**
4
+ * Internal schema representation used by the codegen pipeline.
5
+ *
6
+ * Decoupled from `PayloadFieldSchema` (the runtime shape that arrives
7
+ * via postMessage) because:
8
+ *
9
+ * 1. Static analysis sees richer information — block definitions,
10
+ * relationship targets, hasMany — that the runtime shape may not
11
+ * always carry.
12
+ * 2. The emit phase wants ergonomic structures (TypeScript-like
13
+ * type references) that the runtime never needs.
14
+ *
15
+ * @module @codegen/parser/types
16
+ */
17
+ interface ExtractedSchema {
18
+ readonly globals: readonly ExtractedSlug[];
19
+ readonly collections: readonly ExtractedSlug[];
20
+ /** Diagnostics produced during extraction. Soft warnings only. */
21
+ readonly diagnostics: readonly string[];
22
+ }
23
+ interface ExtractedSlug {
24
+ /** The Payload slug (`'homepage'`, `'posts'`, …). */
25
+ readonly slug: string;
26
+ /** PascalCase type name (`'Homepage'`, `'Post'`, …). */
27
+ readonly typeName: string;
28
+ /** Fully-resolved field tree. */
29
+ readonly fields: readonly ExtractedField[];
30
+ }
31
+ type ExtractedField = ExtractedScalarField | ExtractedArrayField | ExtractedBlocksField | ExtractedGroupField | ExtractedRelationshipField | ExtractedUploadField | ExtractedJsonField | ExtractedSelectField;
32
+ interface ExtractedFieldBase {
33
+ readonly name: string;
34
+ readonly required: boolean;
35
+ readonly localized: boolean;
36
+ }
37
+ interface ExtractedScalarField extends ExtractedFieldBase {
38
+ readonly kind: 'scalar';
39
+ readonly typeRef: 'string' | 'number' | 'boolean' | 'Date' | 'unknown';
40
+ }
41
+ interface ExtractedArrayField extends ExtractedFieldBase {
42
+ readonly kind: 'array';
43
+ readonly fields: readonly ExtractedField[];
44
+ }
45
+ interface ExtractedBlocksField extends ExtractedFieldBase {
46
+ readonly kind: 'blocks';
47
+ readonly blocks: readonly ExtractedBlock[];
48
+ }
49
+ interface ExtractedBlock {
50
+ readonly slug: string;
51
+ readonly typeName: string;
52
+ readonly fields: readonly ExtractedField[];
53
+ }
54
+ interface ExtractedGroupField extends ExtractedFieldBase {
55
+ readonly kind: 'group';
56
+ readonly fields: readonly ExtractedField[];
57
+ }
58
+ interface ExtractedRelationshipField extends ExtractedFieldBase {
59
+ readonly kind: 'relationship';
60
+ readonly target: string | readonly string[];
61
+ readonly hasMany: boolean;
62
+ }
63
+ interface ExtractedUploadField extends ExtractedFieldBase {
64
+ readonly kind: 'upload';
65
+ readonly target: string;
66
+ }
67
+ interface ExtractedJsonField extends ExtractedFieldBase {
68
+ readonly kind: 'json';
69
+ }
70
+ interface ExtractedSelectField extends ExtractedFieldBase {
71
+ readonly kind: 'select';
72
+ readonly options: readonly string[];
73
+ readonly hasMany: boolean;
74
+ }
75
+
76
+ /**
77
+ * Schema-level extraction: open `payload.config.ts`, find every
78
+ * collection and global definition, walk into them.
79
+ *
80
+ * The extractor is deliberately lenient. Payload configurations are
81
+ * full TypeScript programs — a strict parser would have to model
82
+ * conditional types, factory functions, plugin closures. Instead we
83
+ * recognise the *common* shapes (object literal, identifier
84
+ * referencing an imported literal, default export from a sibling
85
+ * file) and emit a diagnostic for anything we can't unwrap.
86
+ *
87
+ * @module @codegen/parser/extract-schema
88
+ */
89
+
90
+ interface ExtractSchemaOptions {
91
+ /** Absolute or relative path to `payload.config.ts`. */
92
+ readonly configPath: string;
93
+ /** When provided, used instead of constructing a fresh ts-morph project. */
94
+ readonly project?: Project;
95
+ /**
96
+ * Optional path to a `tsconfig.json`. When set, ts-morph loads the
97
+ * project's module-resolution configuration so cross-file imports
98
+ * (Homepage from './globals') can be followed.
99
+ */
100
+ readonly tsConfigFilePath?: string;
101
+ }
102
+ declare function extractSchema(options: ExtractSchemaOptions): ExtractedSchema;
103
+
104
+ /**
105
+ * Render `ExtractedSchema` to a TypeScript source string.
106
+ *
107
+ * The output is one self-contained `.ts` file that ships:
108
+ *
109
+ * - one `interface` per global and per collection,
110
+ * - nested `interface` declarations for `group`/`array`/`blocks`,
111
+ * - discriminated unions for `blocks` fields (one variant per slug),
112
+ * - `PayloadCollections` / `PayloadGlobals` maps for slug-keyed
113
+ * access (`PayloadCollections['posts']`), and
114
+ * - a `PayloadSlug` alias.
115
+ *
116
+ * Nothing in the runtime depends on this output — consumers import
117
+ * what they need by name.
118
+ *
119
+ * @module @codegen/emit/emit-types
120
+ */
121
+
122
+ interface EmitOptions {
123
+ /** When true, includes a `@deprecated` JSDoc on localized fields. */
124
+ readonly markLocalizedAsDeprecated?: boolean;
125
+ /** Header text injected at the top of the output. Defaults sensibly. */
126
+ readonly header?: string;
127
+ }
128
+ declare function emitTypes(schema: ExtractedSchema, options?: EmitOptions): string;
129
+
130
+ /**
131
+ * Programmatic codegen API.
132
+ *
133
+ * ```ts
134
+ * import { generateTypes } from 'payload-live-preview/codegen';
135
+ * const { code, diagnostics } = await generateTypes({
136
+ * configPath: 'backend/src/payload.config.ts',
137
+ * outFile: 'frontend/src/payload-types.ts',
138
+ * });
139
+ * ```
140
+ *
141
+ * @module @codegen
142
+ */
143
+
144
+ interface GenerateTypesOptions extends Pick<ExtractSchemaOptions, 'configPath' | 'project' | 'tsConfigFilePath'>, EmitOptions {
145
+ /**
146
+ * If set, the generated code is written to this absolute or
147
+ * cwd-relative path. The function still returns the rendered string
148
+ * in `code` so callers can verify before writing.
149
+ */
150
+ readonly outFile?: string;
151
+ /** Working directory used to resolve relative paths. Defaults to `process.cwd()`. */
152
+ readonly cwd?: string;
153
+ }
154
+ interface GenerateTypesResult {
155
+ readonly code: string;
156
+ readonly diagnostics: readonly string[];
157
+ readonly schema: ExtractedSchema;
158
+ readonly outFile?: string;
159
+ }
160
+ declare function generateTypes(options: GenerateTypesOptions): Promise<GenerateTypesResult>;
161
+
162
+ export { type ExtractedField, type ExtractedSchema, type ExtractedSlug, type GenerateTypesOptions, type GenerateTypesResult, emitTypes, extractSchema, generateTypes };