@payloadcms/figma 0.1.0-alpha.0 → 0.1.0-alpha.1

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 (31) hide show
  1. package/dist/db-content-api/generated/content-api-types.d.ts +644 -3
  2. package/dist/db-content-api/index.d.ts +3 -0
  3. package/dist/db-content-api/index.js +68 -123
  4. package/dist/db-content-api/utilities/clientVersionHeaders.d.ts +7 -0
  5. package/dist/db-content-api/utilities/clientVersionHeaders.js +15 -0
  6. package/dist/db-content-api/utilities/data/atomicOperations.d.ts +16 -0
  7. package/dist/db-content-api/utilities/data/atomicOperations.js +48 -0
  8. package/dist/db-content-api/utilities/data/convertRelationshipIds.d.ts +25 -0
  9. package/dist/db-content-api/utilities/data/convertRelationshipIds.js +109 -0
  10. package/dist/db-content-api/utilities/data/index.js +71 -55
  11. package/dist/db-content-api/utilities/data/isLocaleMap.d.ts +10 -0
  12. package/dist/db-content-api/utilities/data/isLocaleMap.js +13 -0
  13. package/dist/db-content-api/utilities/data/resolveFieldLocalization.d.ts +18 -0
  14. package/dist/db-content-api/utilities/data/resolveFieldLocalization.js +21 -0
  15. package/dist/db-content-api/utilities/data/validateRelationships.js +19 -12
  16. package/dist/db-content-api/utilities/joins.d.ts +6 -8
  17. package/dist/db-content-api/utilities/joins.js +8 -21
  18. package/dist/db-content-api/utilities/schema/buildDocumentSchema.d.ts +21 -4
  19. package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +118 -36
  20. package/dist/db-content-api/utilities/where.d.ts +2 -12
  21. package/dist/db-content-api/utilities/where.js +1 -12
  22. package/dist/utils/load-payload-config.d.ts +2 -2
  23. package/package.json +5 -5
  24. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +0 -10
  25. package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +0 -71
  26. package/dist/db-content-api/utilities/meta/buildMeta.d.ts +0 -41
  27. package/dist/db-content-api/utilities/meta/buildMeta.js +0 -39
  28. package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +0 -16
  29. package/dist/db-content-api/utilities/meta/buildPathTypes.js +0 -243
  30. package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +0 -12
  31. package/dist/db-content-api/utilities/meta/buildUniquePaths.js +0 -60
@@ -2,6 +2,7 @@ import type { BaseDatabaseAdapter, CreateArgs, DatabaseAdapterObj } from 'payloa
2
2
  import createClient from 'openapi-fetch';
3
3
  import type { paths } from './generated/content-api-types.js';
4
4
  import { type AuthMode } from './utilities/auth.js';
5
+ import { type DocumentSchemaWire } from './utilities/schema/buildDocumentSchema.js';
5
6
  type ContentAPIOptions = {
6
7
  allowIDOnCreate?: boolean;
7
8
  auth: AuthMode;
@@ -26,7 +27,9 @@ export type ContentAPIAdapter = {
26
27
  auth: AuthMode;
27
28
  clearDatabase: () => Promise<void>;
28
29
  client: ReturnType<typeof createClient<paths>>;
30
+ clientVersionHeaders: Record<string, string>;
29
31
  contentSystemId: string;
32
+ documentSchema: DocumentSchemaWire;
30
33
  environmentName?: string;
31
34
  idType: 'uuid';
32
35
  notifyLocalJobQueue: boolean;
@@ -7,12 +7,13 @@ import { getGlobalSlug } from './temp-utilities/slug.js';
7
7
  import { addFallbackSort } from './temp-utilities/sorting.js';
8
8
  import { unwrapDocument, unwrapFindResponse } from './temp-utilities/unwrapDocument.js';
9
9
  import { createAuthMiddleware, createErrorMiddleware } from './utilities/auth.js';
10
+ import { getClientVersionHeaders } from './utilities/clientVersionHeaders.js';
10
11
  import { dataToContentAPI, resolveVersionContent } from './utilities/data/index.js';
11
12
  import { validateRelationshipIds } from './utilities/data/validateRelationships.js';
12
13
  import { convertPayloadJoinsToContentAPI } from './utilities/joins.js';
13
14
  import { addFallbackLocale } from './utilities/locale/index.js';
14
- import { buildMeta } from './utilities/meta/buildMeta.js';
15
15
  import { normalizeLocaleInWhere } from './utilities/meta/normalizeLocaleInWhere.js';
16
+ import { buildDocumentSchema } from './utilities/schema/buildDocumentSchema.js';
16
17
  import { convertPayloadWhereToContentAPI } from './utilities/where.js';
17
18
  /**
18
19
  * Heads-up logged locally whenever a job is queued. Queued jobs are executed by Figma's deployed runner, so
@@ -121,21 +122,18 @@ async function createCollection(collectionId) {
121
122
  async function findMany({ collection, joins, limit, locale: localeArg, page, pagination: _pagination, sort, where }) {
122
123
  const locale = addFallbackLocale(localeArg, this.payload);
123
124
  const normalizedWhere = normalizeLocaleInWhere(where, this.payload, collection, locale);
124
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:find', {
125
+ const joinClause = convertPayloadJoinsToContentAPI(this.payload, collection, joins);
126
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:find', {
125
127
  body: {
126
128
  collection,
127
129
  contentSystemId: this.contentSystemId,
128
- join: convertPayloadJoinsToContentAPI(this.payload, collection, joins, locale),
130
+ join: joinClause,
129
131
  limit,
130
132
  locale,
131
133
  page: page ?? 1,
134
+ schema: this.documentSchema,
132
135
  sort: addFallbackSort(sort, this.payload, collection),
133
- where: convertPayloadWhereToContentAPI(normalizedWhere ?? {}),
134
- ...buildMeta(this.payload, {
135
- collection,
136
- locale,
137
- where: normalizedWhere
138
- })
136
+ where: convertPayloadWhereToContentAPI(normalizedWhere ?? {})
139
137
  }
140
138
  });
141
139
  if (error) {
@@ -167,12 +165,9 @@ async function find(args) {
167
165
  // TODO: remove Omit when this PR is released: https://github.com/payloadcms/payload/pull/15183
168
166
  async function findVersions(args) {
169
167
  const sortWithFallback = addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection);
170
- const whereClause = convertPayloadWhereToContentAPI(args.where ?? {}, {
171
- parentToDocumentId: true,
172
- stripVersionPrefix: true
173
- });
168
+ const whereClause = convertPayloadWhereToContentAPI(args.where ?? {});
174
169
  const locale = addFallbackLocale(args.locale, this.payload);
175
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:find', {
170
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:find', {
176
171
  body: {
177
172
  collection: args.collection,
178
173
  contentSystemId: this.contentSystemId,
@@ -181,13 +176,9 @@ async function findVersions(args) {
181
176
  limit: args.limit,
182
177
  locale,
183
178
  page: args.page ?? 1,
179
+ schema: this.documentSchema,
184
180
  sort: sortWithFallback,
185
- where: whereClause,
186
- ...buildMeta(this.payload, {
187
- collection: args.collection,
188
- locale,
189
- where: args.where
190
- })
181
+ where: whereClause
191
182
  }
192
183
  });
193
184
  if (error) {
@@ -229,13 +220,17 @@ async function createVersion(args) {
229
220
  applyDefaults: true,
230
221
  publishedLocale: args.publishedLocale
231
222
  });
223
+ // id/globalType aren't v1 schema fields (id rides as versionDoc.parent)
224
+ delete versionContent.id;
225
+ delete versionContent.globalType;
232
226
  if (args.autosave) {
233
227
  versionContent._payloadAutosave = true;
234
228
  }
235
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:create', {
229
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:create', {
236
230
  body: {
237
231
  collection: args.collectionSlug,
238
232
  contentSystemId: this.contentSystemId,
233
+ schema: this.documentSchema,
239
234
  versionDoc: {
240
235
  createdAt: args.createdAt,
241
236
  latest: true,
@@ -269,12 +264,15 @@ async function updateVersion(args) {
269
264
  const versionContent = dataToContentAPI(this.payload, args.collection, resolvedVersion, {
270
265
  publishedLocale
271
266
  });
272
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:update', {
267
+ delete versionContent.id;
268
+ delete versionContent.globalType;
269
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:update', {
273
270
  body: {
274
271
  collection: args.collection,
275
272
  contentSystemId: this.contentSystemId,
276
273
  createOnMissing: false,
277
274
  locale,
275
+ schema: this.documentSchema,
278
276
  versionDoc: {
279
277
  createdAt: versionMeta.createdAt,
280
278
  latest: versionMeta.latest,
@@ -282,14 +280,7 @@ async function updateVersion(args) {
282
280
  updatedAt: versionMeta.updatedAt,
283
281
  version: versionContent
284
282
  },
285
- where: convertPayloadWhereToContentAPI(where, {
286
- stripVersionPrefix: true
287
- }),
288
- ...buildMeta(this.payload, {
289
- collection: args.collection,
290
- locale,
291
- where
292
- })
283
+ where: convertPayloadWhereToContentAPI(where)
293
284
  }
294
285
  });
295
286
  if (error) {
@@ -314,19 +305,13 @@ async function deleteVersions(args) {
314
305
  throw new Error('deleteVersions requires a collection');
315
306
  }
316
307
  const locale = addFallbackLocale(args.locale, this.payload);
317
- const { error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:delete', {
308
+ const { error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:delete', {
318
309
  body: {
319
310
  collection: args.collection,
320
311
  contentSystemId: this.contentSystemId,
321
312
  locale,
322
- where: convertPayloadWhereToContentAPI(args.where, {
323
- stripVersionPrefix: true
324
- }),
325
- ...buildMeta(this.payload, {
326
- collection: args.collection,
327
- locale,
328
- where: args.where
329
- })
313
+ schema: this.documentSchema,
314
+ where: convertPayloadWhereToContentAPI(args.where)
330
315
  }
331
316
  });
332
317
  if (error) {
@@ -346,7 +331,7 @@ async function findOne(args) {
346
331
  }
347
332
  async function findDistinct(args) {
348
333
  const locale = addFallbackLocale(args.locale, this.payload);
349
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:findDistinct', {
334
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:findDistinct', {
350
335
  body: {
351
336
  collection: args.collection,
352
337
  contentSystemId: this.contentSystemId,
@@ -354,13 +339,9 @@ async function findDistinct(args) {
354
339
  limit: args.limit,
355
340
  locale,
356
341
  page: args.page ?? 1,
342
+ schema: this.documentSchema,
357
343
  sort: addFallbackSort(args.sort, this.payload, args.collection),
358
- where: convertPayloadWhereToContentAPI(args.where ?? {}),
359
- ...buildMeta(this.payload, {
360
- collection: args.collection,
361
- locale,
362
- where: args.where
363
- })
344
+ where: convertPayloadWhereToContentAPI(args.where ?? {})
364
345
  }
365
346
  });
366
347
  if (error) {
@@ -382,7 +363,7 @@ async function updateMany(args) {
382
363
  data: args.data,
383
364
  payload: this.payload
384
365
  });
385
- const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
366
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
386
367
  body: {
387
368
  collection: args.collection,
388
369
  contentSystemId: this.contentSystemId,
@@ -391,14 +372,9 @@ async function updateMany(args) {
391
372
  environmentName: this.environmentName,
392
373
  limit: args.limit,
393
374
  locale,
394
- returning: {},
375
+ schema: this.documentSchema,
395
376
  sort: addFallbackSort(args.sort || '-updatedAt', this.payload, args.collection),
396
- where: convertPayloadWhereToContentAPI(args.where),
397
- ...buildMeta(this.payload, {
398
- collection: args.collection,
399
- locale,
400
- where: args.where
401
- })
377
+ where: convertPayloadWhereToContentAPI(args.where)
402
378
  }
403
379
  });
404
380
  if (error) {
@@ -429,7 +405,7 @@ async function updateOne(args) {
429
405
  data: args.data,
430
406
  payload: this.payload
431
407
  });
432
- const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
408
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
433
409
  body: {
434
410
  collection: args.collection,
435
411
  contentSystemId: this.contentSystemId,
@@ -437,13 +413,8 @@ async function updateOne(args) {
437
413
  doc: dataToContentAPI(this.payload, args.collection, args.data),
438
414
  environmentName: this.environmentName,
439
415
  locale,
440
- returning: {},
441
- where: convertPayloadWhereToContentAPI(where),
442
- ...buildMeta(this.payload, {
443
- collection: args.collection,
444
- locale,
445
- where
446
- })
416
+ schema: this.documentSchema,
417
+ where: convertPayloadWhereToContentAPI(where)
447
418
  }
448
419
  });
449
420
  if (error) {
@@ -468,18 +439,14 @@ async function updateOne(args) {
468
439
  }
469
440
  async function deleteMany(args) {
470
441
  const locale = addFallbackLocale(args.req?.locale, this.payload);
471
- const { error, response: httpResponse } = await this.client.POST('/api/v0/documents:delete', {
442
+ const { error, response: httpResponse } = await this.client.POST('/api/v1/documents:delete', {
472
443
  body: {
473
444
  collection: args.collection,
474
445
  contentSystemId: this.contentSystemId,
475
446
  environmentName: this.environmentName,
476
447
  locale,
477
- where: convertPayloadWhereToContentAPI(args.where),
478
- ...buildMeta(this.payload, {
479
- collection: args.collection,
480
- locale,
481
- where: args.where
482
- })
448
+ schema: this.documentSchema,
449
+ where: convertPayloadWhereToContentAPI(args.where)
483
450
  }
484
451
  });
485
452
  if (error) {
@@ -488,19 +455,14 @@ async function deleteMany(args) {
488
455
  }
489
456
  async function deleteOne(args) {
490
457
  const locale = addFallbackLocale(args.req?.locale, this.payload);
491
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:delete', {
458
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:delete', {
492
459
  body: {
493
460
  collection: args.collection,
494
461
  contentSystemId: this.contentSystemId,
495
462
  environmentName: this.environmentName,
496
463
  locale,
497
- returning: {},
498
- where: convertPayloadWhereToContentAPI(args.where),
499
- ...buildMeta(this.payload, {
500
- collection: args.collection,
501
- locale,
502
- where: args.where
503
- })
464
+ schema: this.documentSchema,
465
+ where: convertPayloadWhereToContentAPI(args.where)
504
466
  }
505
467
  });
506
468
  if (error) {
@@ -541,7 +503,7 @@ async function create(args) {
541
503
  data: args.data,
542
504
  payload: this.payload
543
505
  });
544
- const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:create', {
506
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:create', {
545
507
  body: {
546
508
  collection: args.collection,
547
509
  contentSystemId: this.contentSystemId,
@@ -554,11 +516,7 @@ async function create(args) {
554
516
  },
555
517
  environmentName: this.environmentName,
556
518
  locale,
557
- ...buildMeta(this.payload, {
558
- collection: args.collection,
559
- data: args.data,
560
- locale
561
- })
519
+ schema: this.documentSchema
562
520
  }
563
521
  });
564
522
  if (error) {
@@ -580,7 +538,8 @@ async function clearDatabase() {
580
538
  try {
581
539
  const response = await fetch(getClearDatabaseUrl(this.url, process.env.FIGMA_CONTENT_API_CUTOVER_STATE), {
582
540
  headers: {
583
- 'Content-Type': 'application/json'
541
+ 'Content-Type': 'application/json',
542
+ ...this.clientVersionHeaders
584
543
  },
585
544
  method: 'POST'
586
545
  });
@@ -604,17 +563,13 @@ export function getClearDatabaseUrl(url, cutoverState) {
604
563
  }
605
564
  async function count(args) {
606
565
  const locale = addFallbackLocale(args.locale, this.payload);
607
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:count', {
566
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:count', {
608
567
  body: {
609
568
  collection: args.collection,
610
569
  contentSystemId: this.contentSystemId,
611
570
  locale,
612
- where: convertPayloadWhereToContentAPI(args.where),
613
- ...buildMeta(this.payload, {
614
- collection: args.collection,
615
- locale,
616
- where: args.where
617
- })
571
+ schema: this.documentSchema,
572
+ where: convertPayloadWhereToContentAPI(args.where)
618
573
  }
619
574
  });
620
575
  if (error) {
@@ -629,20 +584,13 @@ async function count(args) {
629
584
  }
630
585
  async function countVersions(args) {
631
586
  const locale = addFallbackLocale(args.locale, this.payload);
632
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/document_versions:count', {
587
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/document_versions:count', {
633
588
  body: {
634
589
  collection: args.collection,
635
590
  contentSystemId: this.contentSystemId,
636
591
  locale,
637
- where: convertPayloadWhereToContentAPI(args.where, {
638
- parentToDocumentId: true,
639
- stripVersionPrefix: true
640
- }),
641
- ...buildMeta(this.payload, {
642
- collection: args.collection,
643
- locale,
644
- where: args.where
645
- })
592
+ schema: this.documentSchema,
593
+ where: convertPayloadWhereToContentAPI(args.where)
646
594
  }
647
595
  });
648
596
  if (error) {
@@ -672,7 +620,7 @@ async function upsert(args) {
672
620
  data: args.data,
673
621
  payload: this.payload
674
622
  });
675
- const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
623
+ const { data: contentAPIResponse, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
676
624
  body: {
677
625
  collection: args.collection,
678
626
  contentSystemId: this.contentSystemId,
@@ -685,13 +633,8 @@ async function upsert(args) {
685
633
  }),
686
634
  environmentName: this.environmentName,
687
635
  locale,
688
- where: convertPayloadWhereToContentAPI(args.where),
689
- ...buildMeta(this.payload, {
690
- collection: args.collection,
691
- data: args.data,
692
- locale,
693
- where: args.where
694
- })
636
+ schema: this.documentSchema,
637
+ where: convertPayloadWhereToContentAPI(args.where)
695
638
  }
696
639
  });
697
640
  if (error) {
@@ -738,12 +681,7 @@ async function updateJobs(args) {
738
681
  const docData = dataToContentAPI(this.payload, 'payload-jobs', data);
739
682
  const sortClause = addFallbackSort(sort || '-updatedAt', this.payload, 'payload-jobs');
740
683
  const whereQuery = convertPayloadWhereToContentAPI(whereClause);
741
- const meta = buildMeta(this.payload, {
742
- collection: 'payload-jobs',
743
- locale: undefined,
744
- where: whereClause
745
- });
746
- const { data: response, error, response: httpResponse } = await this.client.POST('/api/v0/documents:update', {
684
+ const { data: response, error, response: httpResponse } = await this.client.POST('/api/v1/documents:update', {
747
685
  body: {
748
686
  collection: 'payload-jobs',
749
687
  contentSystemId: this.contentSystemId,
@@ -753,10 +691,9 @@ async function updateJobs(args) {
753
691
  ...limit != null && {
754
692
  limit
755
693
  },
756
- returning: {},
694
+ schema: this.documentSchema,
757
695
  sort: sortClause,
758
- where: whereQuery,
759
- ...meta
696
+ where: whereQuery
760
697
  }
761
698
  });
762
699
  if (error) {
@@ -787,8 +724,7 @@ function createGlobal(args) {
787
724
  collection: getGlobalSlug(args.slug),
788
725
  data: {
789
726
  ...args.data,
790
- id: args.slug,
791
- globalType: args.slug
727
+ id: args.slug
792
728
  },
793
729
  where: {
794
730
  id: {
@@ -797,12 +733,17 @@ function createGlobal(args) {
797
733
  }
798
734
  });
799
735
  }
800
- function findGlobal(args) {
801
- return this.findOne({
736
+ async function findGlobal(args) {
737
+ const doc = await this.findOne({
802
738
  collection: getGlobalSlug(args.slug),
803
739
  locale: args.locale,
804
740
  where: args.where ?? {}
805
741
  });
742
+ if (doc != null) {
743
+ ;
744
+ doc.globalType = args.slug;
745
+ }
746
+ return doc;
806
747
  }
807
748
  async function updateGlobal(args) {
808
749
  // TODO: upsert's `createOnMissing` path generates a new `createdAt` on every call,
@@ -879,8 +820,10 @@ export const contentAPIAdapter = (opts)=>({
879
820
  name: 'content-api',
880
821
  defaultIDType: 'text',
881
822
  init: ({ payload })=>{
823
+ const clientVersionHeaders = getClientVersionHeaders();
882
824
  const client = createClient({
883
- baseUrl: opts.url
825
+ baseUrl: opts.url,
826
+ headers: clientVersionHeaders
884
827
  });
885
828
  const middlewareOpts = {
886
829
  auth: opts.auth,
@@ -897,6 +840,7 @@ export const contentAPIAdapter = (opts)=>({
897
840
  beginTransaction: ()=>Promise.resolve(null),
898
841
  clearDatabase: clearDatabase,
899
842
  client,
843
+ clientVersionHeaders,
900
844
  commitTransaction: async ()=>{},
901
845
  connect: connect,
902
846
  contentSystemId: opts.contentSystemId,
@@ -911,6 +855,7 @@ export const contentAPIAdapter = (opts)=>({
911
855
  deleteMany: deleteMany,
912
856
  deleteOne: deleteOne,
913
857
  deleteVersions: deleteVersions,
858
+ documentSchema: buildDocumentSchema(payload.config),
914
859
  environmentName: opts.environmentName,
915
860
  find: find,
916
861
  findDistinct: findDistinct,
@@ -0,0 +1,7 @@
1
+ export declare const FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER = "X-Figma-Payload-Plugin-Version";
2
+ type ClientVersionHeadersArgs = {
3
+ payloadPluginVersion: string;
4
+ };
5
+ export declare function getClientVersionHeaders(): Record<string, string>;
6
+ export declare function buildClientVersionHeaders({ payloadPluginVersion, }: ClientVersionHeadersArgs): Record<string, string>;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ import packageJson from '../../../package.json' with {
2
+ type: 'json'
3
+ };
4
+ // KEEP_IN_SYNC(payload/content-api/src/server/clientVersionTelemetry.ts)
5
+ export const FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER = 'X-Figma-Payload-Plugin-Version';
6
+ export function getClientVersionHeaders() {
7
+ return buildClientVersionHeaders({
8
+ payloadPluginVersion: packageJson.version
9
+ });
10
+ }
11
+ export function buildClientVersionHeaders({ payloadPluginVersion }) {
12
+ return {
13
+ [FIGMA_PAYLOAD_PLUGIN_VERSION_HEADER]: payloadPluginVersion
14
+ };
15
+ }
@@ -0,0 +1,16 @@
1
+ export type AtomicOperator = '$inc' | '$push' | '$remove';
2
+ export declare const ATOMIC_OPERATORS: readonly AtomicOperator[];
3
+ /** Relationship/upload values are lists, so they only ever carry list operators. */
4
+ export declare const RELATIONSHIP_ATOMIC_OPERATORS: readonly ('$push' | '$remove')[];
5
+ /**
6
+ * Recognizes an atomic-operation wrapper, returning its operator and the wrapped
7
+ * value, or `null` when the value is not such a wrapper.
8
+ */
9
+ export declare function matchAtomicOperation<T extends AtomicOperator>(value: unknown, operators: readonly T[]): {
10
+ inner: unknown;
11
+ operator: T;
12
+ } | null;
13
+ /** Whether the value is an atomic-operation wrapper rather than a plain value. */
14
+ export declare function isAtomicOperation(value: unknown, operators: readonly AtomicOperator[]): boolean;
15
+ /** Returns the wrapped value of an atomic operation, or the value itself. */
16
+ export declare function unwrapAtomicOperation(value: unknown, operators: readonly AtomicOperator[]): unknown;
@@ -0,0 +1,48 @@
1
+ // Payload expresses an atomic field update as a single-key wrapper around the
2
+ // value — e.g. `{ $push: ['id'] }` on a has-many relationship, `{ $inc: 1 }` on a
3
+ // number field. Which operators are legal depends on the field type, so callers
4
+ // pass the set they accept; the default is every operator the adapter knows about.
5
+ export const ATOMIC_OPERATORS = [
6
+ '$inc',
7
+ '$push',
8
+ '$remove'
9
+ ];
10
+ /** Relationship/upload values are lists, so they only ever carry list operators. */ export const RELATIONSHIP_ATOMIC_OPERATORS = [
11
+ '$push',
12
+ '$remove'
13
+ ];
14
+ /**
15
+ * Recognizes an atomic-operation wrapper, returning its operator and the wrapped
16
+ * value, or `null` when the value is not such a wrapper.
17
+ */ export function matchAtomicOperation(value, operators) {
18
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
19
+ return null;
20
+ }
21
+ const keys = Object.keys(value);
22
+ if (keys.length !== 1) {
23
+ return null;
24
+ }
25
+ const key = keys[0];
26
+ if (!isOneOf(key, operators)) {
27
+ return null;
28
+ }
29
+ return {
30
+ inner: value[key],
31
+ operator: key
32
+ };
33
+ }
34
+ /** Whether the value is an atomic-operation wrapper rather than a plain value. */ export function isAtomicOperation(value, operators) {
35
+ return matchAtomicOperation(value, operators) !== null;
36
+ }
37
+ /** Returns the wrapped value of an atomic operation, or the value itself. */ export function unwrapAtomicOperation(value, operators) {
38
+ const match = matchAtomicOperation(value, operators);
39
+ return match ? match.inner : value;
40
+ }
41
+ function isOneOf(value, options) {
42
+ for (const option of options){
43
+ if (option === value) {
44
+ return true;
45
+ }
46
+ }
47
+ return false;
48
+ }
@@ -0,0 +1,25 @@
1
+ import type { Payload, RelationshipField, UploadField } from 'payload';
2
+ type Direction = 'fromWire' | 'toWire';
3
+ export declare function convertRelationshipFieldIdsFromWire(options: {
4
+ field: RelationshipField | UploadField;
5
+ payload: Payload;
6
+ value: unknown;
7
+ }): unknown;
8
+ export declare function convertRelationshipFieldIdsToWire(options: {
9
+ field: RelationshipField | UploadField;
10
+ payload: Payload;
11
+ value: unknown;
12
+ }): unknown;
13
+ /**
14
+ * Converts the id(s) inside a relationship/upload field value between Payload's
15
+ * representation (numeric ids kept as numbers) and the Content API wire form
16
+ * (all ids as strings). No-op for uuid/text targets. Preserves has-many arrays,
17
+ * polymorphic shapes, localized locale-maps, and atomic operators.
18
+ */
19
+ export declare function convertRelationshipFieldIds(options: {
20
+ direction: Direction;
21
+ field: RelationshipField | UploadField;
22
+ payload: Payload;
23
+ value: unknown;
24
+ }): unknown;
25
+ export {};