@livepreso/api 6.53.0 → 6.53.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 (33) hide show
  1. package/.rush/temp/chunked-rush-logs/api.build.chunks.jsonl +9 -0
  2. package/.rush/temp/operation/build/all.log +9 -0
  3. package/.rush/temp/operation/build/error.log +3 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +9 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +11 -2
  7. package/CHANGELOG.json +15 -0
  8. package/CHANGELOG.md +9 -1
  9. package/cjs/collections/base.js +15 -1
  10. package/cjs/collections/base.js.map +1 -1
  11. package/cjs/collections/base.spec.js +61 -0
  12. package/cjs/collections/base.spec.js.map +1 -1
  13. package/cjs/models/base.js +54 -12
  14. package/cjs/models/base.js.map +1 -1
  15. package/cjs/models/base.spec.js +28 -0
  16. package/cjs/models/base.spec.js.map +1 -1
  17. package/cjs/models/deck-version.js +14 -5
  18. package/cjs/models/deck-version.js.map +1 -1
  19. package/cjs/presentation/presentation-section.js +1 -1
  20. package/cjs/presentation/presentation-section.js.map +1 -1
  21. package/cjs/presentation/presentation-slide.js +2 -2
  22. package/cjs/presentation/presentation-slide.js.map +1 -1
  23. package/package.json +1 -1
  24. package/rush-logs/api.build.cache.log +1 -0
  25. package/rush-logs/api.build.error.log +3 -0
  26. package/rush-logs/api.build.log +9 -0
  27. package/src/collections/base.js +13 -2
  28. package/src/collections/base.spec.js +37 -0
  29. package/src/models/base.js +38 -11
  30. package/src/models/base.spec.js +18 -0
  31. package/src/models/deck-version.js +7 -4
  32. package/src/presentation/presentation-section.js +1 -1
  33. package/src/presentation/presentation-slide.js +2 -2
@@ -225,4 +225,41 @@ describe("fetchAll", () => {
225
225
  expect(baseCollection.first().id).toEqual(11);
226
226
  expect(baseCollection.last().id).toEqual(30);
227
227
  });
228
+
229
+ it("should serialize collection models with urls", async () => {
230
+ G(BaseCollection.extend({ model: "TestModel" }), "TestCollection");
231
+ G(
232
+ BaseModel.extend({
233
+ modelName: "bar",
234
+ children: { test: "TestModel" },
235
+ collections: { tests: "TestCollection" },
236
+ }),
237
+ "TestModel",
238
+ );
239
+
240
+ const Collection = G(BaseCollection.extend({ model: "TestModel" }));
241
+ const baseCollection = new Collection([
242
+ {
243
+ id: 1,
244
+ url: "/api/bar/1/",
245
+ test: { id: 1, url: "/api/baz/1/" },
246
+ tests: [{ id: 2, test: { id: 4 } }],
247
+ },
248
+ {
249
+ id: 2,
250
+ url: "/api/bar/2/",
251
+ test: { id: 2, url: "/api/baz/2/" },
252
+ tests: [],
253
+ },
254
+ ]);
255
+ expect(baseCollection.serialize({ urlsOnly: true })).toEqual([
256
+ {
257
+ id: 1,
258
+ test: "/api/bar/1/",
259
+ url: "/api/bar/1/",
260
+ tests: ["/api/bar/2/"],
261
+ },
262
+ { id: 2, test: "/api/bar/2/", url: "/api/bar/2/", tests: [] },
263
+ ]);
264
+ });
228
265
  });
@@ -242,7 +242,7 @@ export const BaseModel = Model.extend(
242
242
  getIDFromURL(url, resource = "") {
243
243
  const resourceURL = resource || this.getResourceURL();
244
244
 
245
- if (!url || !resourceURL) {
245
+ if (typeof url !== "string" || !resourceURL) {
246
246
  return null;
247
247
  }
248
248
 
@@ -693,6 +693,10 @@ export const BaseModel = Model.extend(
693
693
  return {};
694
694
  }
695
695
 
696
+ // Urls only will build a model without its children/collections expanded -
697
+ // it will return urls instead of the full model.
698
+ const { urlsOnly = false } = opts ?? {};
699
+
696
700
  const data = Model.prototype.serialize.apply(this, arguments);
697
701
  data.url = this.url();
698
702
 
@@ -706,24 +710,47 @@ export const BaseModel = Model.extend(
706
710
  return object;
707
711
  }, {});
708
712
 
709
- Object.keys(this._unsetCollections).forEach((key) => {
710
- if (this._unsetCollections[key].canBeEmpty && !this._values[key]) {
713
+ const allCollectionKeys = [
714
+ ...Object.keys(this._unsetCollections),
715
+ ...Object.keys(this._collections),
716
+ ];
717
+
718
+ for (const key of allCollectionKeys) {
719
+ const constructor = this._unsetCollections[key];
720
+
721
+ if (urlsOnly && this[key]) {
722
+ if (typeof this._values[key] === "string") {
723
+ derived[key] = this._values[key];
724
+ } else {
725
+ derived[key] = this[key].map((m) => m.url());
726
+ }
727
+ } else if (!constructor) {
728
+ continue;
729
+ } else if (constructor.canBeEmpty && !this._values[key]) {
711
730
  derived[key] = [];
712
731
  }
713
- });
732
+ }
714
733
 
715
- Object.keys(this._unsetChildren).forEach((key) => {
716
- if (
717
- this._unsetChildren[key].canBeEmpty &&
718
- !this._values[key] &&
719
- this[key]
720
- ) {
734
+ const allChildrenKeys = [
735
+ ...Object.keys(this._unsetChildren),
736
+ ...(urlsOnly ? Object.keys(this._children) : []),
737
+ ];
738
+
739
+ for (const key of allChildrenKeys) {
740
+ const constructor = this._unsetChildren[key];
741
+
742
+ if (urlsOnly && this[key]) {
743
+ derived[key] = this[key].url();
744
+ } else if (!constructor) {
745
+ continue;
746
+ } else if (constructor.canBeEmpty && !this._values[key] && this[key]) {
721
747
  derived[key] = this[key].url();
722
748
  }
723
- });
749
+ }
724
750
 
725
751
  return _.extend(data, derived);
726
752
  },
753
+
727
754
  // Safely retrieve the url from a child or collection that may or may not
728
755
  // be hydrated
729
756
  _retrieveURL(item) {
@@ -426,3 +426,21 @@ describe(".matchesURL", () => {
426
426
  expect(ActivityModel.matchesURL(url)).toEqual(true);
427
427
  });
428
428
  });
429
+
430
+ it("should allow serializing collections with urls only", () => {
431
+ G(BaseModel.extend({ modelName: "baz" }), "TestModel");
432
+ G(BaseCollection.extend({ model: "TestModel" }), "TestCollection");
433
+ const Model = G(
434
+ BaseModel.extend({ collections: { tests: "TestCollection" } }),
435
+ );
436
+ const model = new Model({
437
+ tests: [
438
+ { id: 1, url: "/api/baz/1/" },
439
+ { id: 2, url: "/api/baz/2/" },
440
+ ],
441
+ });
442
+ expect(model.serialize({ urlsOnly: true })).toEqual({
443
+ url: null,
444
+ tests: ["/api/baz/1/", "/api/baz/2/"],
445
+ });
446
+ });
@@ -141,7 +141,7 @@ export const DeckVersionModel = BaseModel.extend(
141
141
  Object.keys(this.getSafeAttrs()).length === 1 ||
142
142
  !this.index_asset
143
143
  ) {
144
- return this.fetch();
144
+ return this.fetch({ fetchTemplates: false });
145
145
  }
146
146
  return null;
147
147
  })
@@ -200,14 +200,17 @@ export const DeckVersionModel = BaseModel.extend(
200
200
  return Promise.all(imports);
201
201
  },
202
202
 
203
- fetch() {
204
- const fetch = BaseModel.prototype.fetch.apply(this, arguments);
203
+ fetch(opts, ...other) {
204
+ const fetch = BaseModel.prototype.fetch.apply(this, [opts, ...other]);
205
+ const shouldFetchTemplates = opts?.fetchTemplates ?? true;
205
206
 
206
207
  return Promise.resolve(fetch).tap(() => {
207
208
  // `template_set` used to come on the deckversion response, but we have since
208
209
  // decided to request it separately (this helps with caching). To keep the app
209
210
  // working with minimal changes, we're making the extra request here.
210
- return this.template_set.fetch();
211
+ if (shouldFetchTemplates) {
212
+ return this.template_set.fetch();
213
+ }
211
214
  });
212
215
  },
213
216
 
@@ -467,7 +467,7 @@ PresentationSection.createFromManifestImpostor = function (
467
467
  const slides = section.slides || [];
468
468
  section.slides = null;
469
469
 
470
- const projectSection = project?.sections.find((s) => s.key === section.key);
470
+ const projectSection = project?.sections.find((s) => s.key === project.key);
471
471
 
472
472
  const presentationSection = new PresentationSection({
473
473
  id: parseInt(_.uniqueId(), 10),
@@ -372,13 +372,13 @@ PresentationSlide.createFromManifestJSON = function (
372
372
 
373
373
  PresentationSlide.createFromManifestImpostor = function (
374
374
  slide,
375
- section,
375
+ _section,
376
376
  project,
377
377
  index,
378
378
  sectionID,
379
379
  ) {
380
380
  const projectSection = project?.sections?.find?.(
381
- (s) => s.key === section.key,
381
+ (s) => s.key === project.key,
382
382
  );
383
383
  const projectSlide = projectSection?.slides?.find?.(
384
384
  (s) => s.key === slide.key,