@gmb/bitmark-parser-generator 5.4.0 → 5.5.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.
package/dist/index.cjs CHANGED
@@ -489,6 +489,7 @@ var BitType = {
489
489
  pageHero: "page-hero",
490
490
  pageOpenBook: "page-open-book",
491
491
  pageOpenBookList: "page-open-book-list",
492
+ printBook: "print-book",
492
493
  openBookChapter: "open-book-chapter",
493
494
  pagePerson: "page-person",
494
495
  pageProduct: "page-product",
@@ -1302,6 +1303,7 @@ var propertyKeys = {
1302
1303
  property_internalPrintPdf: "@internalPrintPdf",
1303
1304
  property_hasPrintRestriction: "@hasPrintRestriction",
1304
1305
  property_enforceUpdateOverUserInput: "@enforceUpdateOverUserInput",
1306
+ property_extractorExtractionTimestamp: "@extractorExtractionTimestamp",
1305
1307
  property_isCaseSensitive: "@isCaseSensitive",
1306
1308
  property_isInfoOnly: "@isInfoOnly",
1307
1309
  property_isPublic: "@isPublic",
@@ -1339,6 +1341,7 @@ var propertyKeys = {
1339
1341
  property_mute: "@mute",
1340
1342
  property_padletId: "@padletId",
1341
1343
  property_page: "@page",
1344
+ property_printParentChapterLevel: "@printParentChapterLevel",
1342
1345
  property_pageNo: "@pageNo",
1343
1346
  property_partialAnswer: "@partialAnswer",
1344
1347
  property_partner: "@partner",
@@ -3478,6 +3481,12 @@ var GROUPS = {
3478
3481
  description: "If true, prioritize new content over legacy content from the instance API",
3479
3482
  format: TagFormat.boolean,
3480
3483
  defaultValue: "false"
3484
+ },
3485
+ {
3486
+ key: ConfigKey.property_extractorExtractionTimestamp,
3487
+ description: "Extraction timestamps for book conversion",
3488
+ format: TagFormat.plainText,
3489
+ maxCount: Count.infinity
3481
3490
  }
3482
3491
  ]
3483
3492
  },
@@ -6874,6 +6883,12 @@ var BITS = {
6874
6883
  key: ConfigKey.property_buttonCaption,
6875
6884
  description: "The caption of the print button",
6876
6885
  format: TagFormat.plainText
6886
+ },
6887
+ {
6888
+ key: ConfigKey.property_printParentChapterLevel,
6889
+ description: "The parent chapter level to print",
6890
+ format: TagFormat.number,
6891
+ defaultValue: "-1"
6877
6892
  }
6878
6893
  ]
6879
6894
  },
@@ -7454,6 +7469,39 @@ var BITS = {
7454
7469
  }
7455
7470
  ]
7456
7471
  },
7472
+ [BitType.printBook]: {
7473
+ since: "5.5.0",
7474
+ baseBitType: BitType.article,
7475
+ description: "Print book bit, used to create pages that open books without author information in articles or books",
7476
+ tags: [
7477
+ {
7478
+ key: ConfigKey.property_slug,
7479
+ description: "Slug for the book, used to identify the book in the system",
7480
+ format: TagFormat.plainText
7481
+ },
7482
+ {
7483
+ key: ConfigKey.property_book,
7484
+ description: "Book reference for the page, used to link to a specific book",
7485
+ format: TagFormat.plainText,
7486
+ chain: [
7487
+ {
7488
+ key: ConfigKey.tag_reference,
7489
+ description: "Reference tag for the book, used to link to the book in the system",
7490
+ maxCount: 2
7491
+ }
7492
+ ]
7493
+ },
7494
+ {
7495
+ /* Allow incorrectly chained reference tag */
7496
+ key: ConfigKey.tag_reference,
7497
+ description: "Reference tag for the book, used to link to the book in the system"
7498
+ },
7499
+ {
7500
+ key: ConfigKey.property_buttonCaption,
7501
+ description: "Caption for the button, used to define the text displayed on the button"
7502
+ }
7503
+ ]
7504
+ },
7457
7505
  [BitType.openBookChapter]: {
7458
7506
  since: "4.16.0",
7459
7507
  baseBitType: BitType.pageOpenBook,
@@ -10349,7 +10397,7 @@ var instance2 = new Config();
10349
10397
  // src/generated/package_info.ts
10350
10398
  var PACKAGE_INFO = {
10351
10399
  "name": "@gmb/bitmark-parser-generator",
10352
- "version": "5.4.0",
10400
+ "version": "5.5.0",
10353
10401
  "author": "Get More Brain Ltd",
10354
10402
  "license": "ISC",
10355
10403
  "description": "A bitmark parser and generator using Peggy.js"
@@ -10972,6 +11020,8 @@ var NodeType = {
10972
11020
  hasPrintRestrictionValue: "hasPrintRestrictionValue",
10973
11021
  enforceUpdateOverUserInput: "enforceUpdateOverUserInput",
10974
11022
  enforceUpdateOverUserInputValue: "enforceUpdateOverUserInputValue",
11023
+ extractorExtractionTimestamp: "extractorExtractionTimestamp",
11024
+ extractorExtractionTimestampValue: "extractorExtractionTimestampValue",
10975
11025
  isCaseSensitive: "isCaseSensitive",
10976
11026
  isCommented: "isCommented",
10977
11027
  isCorrect: "isCorrect",
@@ -11075,6 +11125,8 @@ var NodeType = {
11075
11125
  pageNumber: "pageNumber",
11076
11126
  pageNumberValue: "pageNumberValue",
11077
11127
  pageValue: "pageValue",
11128
+ printParentChapterLevel: "printParentChapterLevel",
11129
+ printParentChapterLevelValue: "printParentChapterLevelValue",
11078
11130
  pairs: "pairs",
11079
11131
  pairsValue: "pairsValue",
11080
11132
  parent: "parent",
@@ -24854,6 +24906,12 @@ var Builder = class extends BaseBuilder {
24854
24906
  data.enforceUpdateOverUserInput,
24855
24907
  options
24856
24908
  ),
24909
+ extractorExtractionTimestamp: this.toAstProperty(
24910
+ bitType,
24911
+ ConfigKey.property_extractorExtractionTimestamp,
24912
+ data.extractorExtractionTimestamp,
24913
+ options
24914
+ ),
24857
24915
  tocResource: this.toAstProperty(
24858
24916
  bitType,
24859
24917
  ConfigKey.property_tocResource,
@@ -24867,6 +24925,12 @@ var Builder = class extends BaseBuilder {
24867
24925
  options
24868
24926
  ),
24869
24927
  page: this.toAstProperty(bitType, ConfigKey.property_page, data.page, options),
24928
+ printParentChapterLevel: this.toAstProperty(
24929
+ bitType,
24930
+ ConfigKey.property_printParentChapterLevel,
24931
+ data.printParentChapterLevel,
24932
+ options
24933
+ ),
24870
24934
  platformBrandTarget: this.toAstProperty(
24871
24935
  bitType,
24872
24936
  ConfigKey.property_platformBrandTarget,
@@ -30537,6 +30601,7 @@ var JsonGenerator = class extends AstWalkerGenerator {
30537
30601
  BitType.pageFooter,
30538
30602
  BitType.pageOpenBook,
30539
30603
  BitType.pagePerson,
30604
+ BitType.printBook,
30540
30605
  BitType.pageProduct,
30541
30606
  BitType.pageProductList,
30542
30607
  BitType.pageProductVideo,
@@ -30557,6 +30622,9 @@ var JsonGenerator = class extends AstWalkerGenerator {
30557
30622
  if (instance2.isOfBitType(bitType, BitType.tocContent)) {
30558
30623
  if (bitJson.tocContent == null) bitJson.tocContent = [];
30559
30624
  }
30625
+ if (instance2.isOfBitType(bitType, BitType.printThisChapter)) {
30626
+ if (bitJson.printParentChapterLevel == null) bitJson.printParentChapterLevel = -1;
30627
+ }
30560
30628
  if (instance2.isOfBitType(bitType, BitType.book)) {
30561
30629
  if (bitJson.maxTocChapterLevel == null) bitJson.maxTocChapterLevel = -1;
30562
30630
  if (bitJson.hasPrintRestriction == null) bitJson.hasPrintRestriction = true;
@@ -39028,6 +39096,7 @@ var JsonFileGenerator = class {
39028
39096
  var import_node_path3 = __toESM(require("path"), 1);
39029
39097
  var import_superenum50 = require("@ncoderz/superenum");
39030
39098
  var import_fs_extra3 = __toESM(require("fs-extra"), 1);
39099
+ var normalizeCardKey = (cardSetKey) => stringUtils.camelToKebab(cardSetKey);
39031
39100
  var ConfigBuilder = class {
39032
39101
  build(options) {
39033
39102
  const opts = Object.assign({}, options);
@@ -39068,8 +39137,10 @@ var ConfigBuilder = class {
39068
39137
  const outputFolder = opts.outputDir ?? "assets/config";
39069
39138
  const outputFolderBits = import_node_path3.default.join(outputFolder, "bits");
39070
39139
  const outputFolderGroups = import_node_path3.default.join(outputFolder, "partials");
39140
+ const outputFolderCards = import_node_path3.default.join(outputFolder, "cards");
39071
39141
  import_fs_extra3.default.ensureDirSync(outputFolderBits);
39072
39142
  import_fs_extra3.default.ensureDirSync(outputFolderGroups);
39143
+ import_fs_extra3.default.ensureDirSync(outputFolderCards);
39073
39144
  const bitsFiles = import_fs_extra3.default.readdirSync(outputFolderBits).filter((f) => f.endsWith(".jsonc"));
39074
39145
  for (const file of bitsFiles) {
39075
39146
  import_fs_extra3.default.removeSync(import_node_path3.default.join(outputFolderBits, file));
@@ -39078,7 +39149,18 @@ var ConfigBuilder = class {
39078
39149
  for (const file of partialsFiles) {
39079
39150
  import_fs_extra3.default.removeSync(import_node_path3.default.join(outputFolderGroups, file));
39080
39151
  }
39152
+ const cardsFiles = import_fs_extra3.default.readdirSync(outputFolderCards).filter((f) => f.endsWith(".jsonc"));
39153
+ for (const file of cardsFiles) {
39154
+ import_fs_extra3.default.removeSync(import_node_path3.default.join(outputFolderCards, file));
39155
+ }
39081
39156
  const fileWrites = [];
39157
+ const tagEntriesTypeOrder = [
39158
+ BitTagConfigKeyType.tag,
39159
+ BitTagConfigKeyType.property,
39160
+ BitTagConfigKeyType.resource,
39161
+ BitTagConfigKeyType.group,
39162
+ BitTagConfigKeyType.unknown
39163
+ ];
39082
39164
  const resolveGroupReferences = (groupKey) => {
39083
39165
  if (squashedGroups.has(groupKey)) {
39084
39166
  const replacements = squashedGroups.get(groupKey);
@@ -39183,6 +39265,38 @@ var ConfigBuilder = class {
39183
39265
  tags2.push(t);
39184
39266
  return tags2;
39185
39267
  };
39268
+ const serializeCardSet = (cardSetKey) => {
39269
+ const cardSetConfig = CARDSETS[cardSetKey];
39270
+ if (!cardSetConfig) return void 0;
39271
+ const normalizedKey = normalizeCardKey(cardSetKey);
39272
+ const sides = cardSetConfig.variants.map((variantList) => {
39273
+ const variants = variantList.map((variant) => {
39274
+ const variantTags = [];
39275
+ const variantTagEntries = Object.entries(variant.tags ?? []).sort((a, b) => {
39276
+ const tagA = a[1];
39277
+ const tagB = b[1];
39278
+ const typeA = typeFromConfigKey(tagA.key);
39279
+ const typeB = typeFromConfigKey(tagB.key);
39280
+ const typeOrder = tagEntriesTypeOrder.indexOf(typeA) - tagEntriesTypeOrder.indexOf(typeB);
39281
+ return typeOrder;
39282
+ });
39283
+ for (const [, variantTag] of variantTagEntries) {
39284
+ variantTags.push(...processTagEntries(variantTag, []));
39285
+ }
39286
+ return {
39287
+ tags: variantTags,
39288
+ repeatCount: variant.repeatCount ?? 1,
39289
+ bodyAllowed: variant.bodyAllowed ?? true,
39290
+ bodyRequired: variant.bodyRequired ?? false
39291
+ };
39292
+ });
39293
+ return { variants };
39294
+ });
39295
+ return {
39296
+ key: normalizedKey,
39297
+ sides
39298
+ };
39299
+ };
39186
39300
  for (const bt of bitGroupConfigKeys) {
39187
39301
  const bitType = instance2.getBitType(bt);
39188
39302
  const _bitConfig = BITS[bitType];
@@ -39215,13 +39329,6 @@ var ConfigBuilder = class {
39215
39329
  for (const b of bitConfigs) {
39216
39330
  const resolvedBitConfig = instance2.getBitConfig(b.bitType);
39217
39331
  const tags2 = [];
39218
- const tagEntriesTypeOrder = [
39219
- BitTagConfigKeyType.tag,
39220
- BitTagConfigKeyType.property,
39221
- BitTagConfigKeyType.resource,
39222
- BitTagConfigKeyType.group,
39223
- BitTagConfigKeyType.unknown
39224
- ];
39225
39332
  const tagEntries = Object.entries(b.tags ?? []).sort((a, b2) => {
39226
39333
  const tagA = a[1];
39227
39334
  const tagB = b2[1];
@@ -39253,6 +39360,10 @@ var ConfigBuilder = class {
39253
39360
  tags2.push(...processTagEntries(tag, []));
39254
39361
  }
39255
39362
  }
39363
+ let cardRef;
39364
+ if (b.cardSet && CARDSETS[b.cardSet]) {
39365
+ cardRef = normalizeCardKey(b.cardSet);
39366
+ }
39256
39367
  const bitJson = {
39257
39368
  name: b.bitType,
39258
39369
  description: b.description ?? "",
@@ -39270,7 +39381,8 @@ var ConfigBuilder = class {
39270
39381
  footerAllowed: resolvedBitConfig.footerAllowed ?? true,
39271
39382
  footerRequired: resolvedBitConfig.footerRequired ?? false,
39272
39383
  resourceAttachmentAllowed: resolvedBitConfig.resourceAttachmentAllowed ?? true,
39273
- tags: tags2
39384
+ tags: tags2,
39385
+ ...cardRef ? { card: cardRef } : {}
39274
39386
  };
39275
39387
  const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
39276
39388
  const str = JSON.stringify(bitJson, null, 2);
@@ -39280,7 +39392,7 @@ var ConfigBuilder = class {
39280
39392
  for (const g of groupConfigs2) {
39281
39393
  const tags2 = [];
39282
39394
  const groupKey = stringUtils.camelToKebab(g.key);
39283
- const tagEntriesTypeOrder = [
39395
+ const tagEntriesTypeOrder2 = [
39284
39396
  BitTagConfigKeyType.tag,
39285
39397
  BitTagConfigKeyType.property,
39286
39398
  BitTagConfigKeyType.resource,
@@ -39289,7 +39401,7 @@ var ConfigBuilder = class {
39289
39401
  const tagEntries = Object.entries(g.tags ?? []).sort((a, b) => {
39290
39402
  const tagA = a[1];
39291
39403
  const tagB = b[1];
39292
- const typeOrder = tagEntriesTypeOrder.indexOf(tagA.type) - tagEntriesTypeOrder.indexOf(tagB.type);
39404
+ const typeOrder = tagEntriesTypeOrder2.indexOf(tagA.type) - tagEntriesTypeOrder2.indexOf(tagB.type);
39293
39405
  return typeOrder;
39294
39406
  });
39295
39407
  for (const [_tagKey, tag] of tagEntries) {
@@ -39337,6 +39449,15 @@ var ConfigBuilder = class {
39337
39449
  }
39338
39450
  };
39339
39451
  writeGroupConfigs(groupConfigs);
39452
+ const writeCardConfigs = () => {
39453
+ for (const cardSetKey of Object.keys(CARDSETS)) {
39454
+ const cardJson = serializeCardSet(cardSetKey);
39455
+ if (!cardJson) continue;
39456
+ const output = import_node_path3.default.join(outputFolderCards, `${cardJson.key}.jsonc`);
39457
+ const str = JSON.stringify(cardJson, null, 2);
39458
+ fileWrites.push(import_fs_extra3.default.writeFile(output, str));
39459
+ }
39460
+ };
39340
39461
  const writeBitsAsGroupConfigs = (bitsAsGroupConfigs) => {
39341
39462
  for (const b of bitsAsGroupConfigs) {
39342
39463
  const groupKey = `group-${b.bitType}`;
@@ -39353,13 +39474,6 @@ var ConfigBuilder = class {
39353
39474
  });
39354
39475
  }
39355
39476
  }
39356
- const tagEntriesTypeOrder = [
39357
- BitTagConfigKeyType.tag,
39358
- BitTagConfigKeyType.property,
39359
- BitTagConfigKeyType.resource,
39360
- BitTagConfigKeyType.group,
39361
- BitTagConfigKeyType.unknown
39362
- ];
39363
39477
  const tagEntries = Object.entries(b.tags ?? []).sort((a, b2) => {
39364
39478
  const tagA = a[1];
39365
39479
  const tagB = b2[1];
@@ -39390,6 +39504,7 @@ var ConfigBuilder = class {
39390
39504
  }
39391
39505
  };
39392
39506
  writeBitsAsGroupConfigs(bitGroupConfigs);
39507
+ writeCardConfigs();
39393
39508
  Promise.all(fileWrites).then(() => {
39394
39509
  const validationErrors = this.validateConfigTree(outputFolder);
39395
39510
  if (validationErrors.length > 0) {
@@ -39415,6 +39530,7 @@ var ConfigBuilder = class {
39415
39530
  const errors = [];
39416
39531
  const outputFolderBits = import_node_path3.default.join(outputFolder, "bits");
39417
39532
  const outputFolderGroups = import_node_path3.default.join(outputFolder, "partials");
39533
+ const outputFolderCards = import_node_path3.default.join(outputFolder, "cards");
39418
39534
  const availableGroups = /* @__PURE__ */ new Set();
39419
39535
  if (import_fs_extra3.default.existsSync(outputFolderGroups)) {
39420
39536
  const groupFiles = import_fs_extra3.default.readdirSync(outputFolderGroups).filter((f) => f.endsWith(".jsonc"));
@@ -39423,16 +39539,22 @@ var ConfigBuilder = class {
39423
39539
  availableGroups.add(groupName);
39424
39540
  }
39425
39541
  }
39542
+ const availableCards = /* @__PURE__ */ new Set();
39543
+ const cardFiles = import_fs_extra3.default.existsSync(outputFolderCards) ? import_fs_extra3.default.readdirSync(outputFolderCards).filter((f) => f.endsWith(".jsonc")) : [];
39544
+ for (const file of cardFiles) {
39545
+ const cardName = file.replace(".jsonc", "");
39546
+ availableCards.add(cardName);
39547
+ }
39426
39548
  const checkTags = (tags2, filePath, lineOffset) => {
39427
39549
  for (let i = 0; i < tags2.length; i++) {
39428
39550
  const tag = tags2[i];
39429
- if (tag.type === "group") {
39551
+ if (tag?.type === "group" && tag.key) {
39430
39552
  if (!availableGroups.has(tag.key)) {
39431
39553
  const line = lineOffset + i + 1;
39432
39554
  errors.push(`Missing group reference '${tag.key}' in ${filePath}:${line}`);
39433
39555
  }
39434
39556
  }
39435
- if (tag.tags && Array.isArray(tag.tags)) {
39557
+ if (Array.isArray(tag?.tags)) {
39436
39558
  checkTags(tag.tags, filePath, lineOffset + i + 1);
39437
39559
  }
39438
39560
  }
@@ -39447,6 +39569,27 @@ var ConfigBuilder = class {
39447
39569
  if (config.tags && Array.isArray(config.tags)) {
39448
39570
  checkTags(config.tags, `bits/${file}`, 15);
39449
39571
  }
39572
+ if (typeof config.card === "string") {
39573
+ if (!availableCards.has(config.card)) {
39574
+ errors.push(`Missing card file '${config.card}' referenced in bits/${file}`);
39575
+ }
39576
+ } else if (config.card?.sides && Array.isArray(config.card.sides)) {
39577
+ config.card.sides.forEach((side, sideIdx) => {
39578
+ const variants = side.variants;
39579
+ if (Array.isArray(variants)) {
39580
+ variants.forEach((variant, variantIdx) => {
39581
+ const variantTags = variant.tags;
39582
+ if (Array.isArray(variantTags)) {
39583
+ checkTags(
39584
+ variantTags,
39585
+ `bits/${file} (card side ${sideIdx}, variant ${variantIdx})`,
39586
+ 15
39587
+ );
39588
+ }
39589
+ });
39590
+ }
39591
+ });
39592
+ }
39450
39593
  } catch (err) {
39451
39594
  errors.push(`Failed to parse ${file}: ${err}`);
39452
39595
  }
@@ -39467,6 +39610,38 @@ var ConfigBuilder = class {
39467
39610
  }
39468
39611
  }
39469
39612
  }
39613
+ if (cardFiles.length > 0) {
39614
+ for (const file of cardFiles) {
39615
+ const filePath = import_node_path3.default.join(outputFolderCards, file);
39616
+ try {
39617
+ const content = import_fs_extra3.default.readFileSync(filePath, "utf-8");
39618
+ const config = JSON.parse(content);
39619
+ const expectedKey = file.replace(".jsonc", "");
39620
+ if (config.key && config.key !== expectedKey) {
39621
+ errors.push(`Card key mismatch in cards/${file}: expected '${expectedKey}'`);
39622
+ }
39623
+ if (Array.isArray(config.sides)) {
39624
+ config.sides.forEach((side, sideIdx) => {
39625
+ const variants = side.variants;
39626
+ if (Array.isArray(variants)) {
39627
+ variants.forEach((variant, variantIdx) => {
39628
+ const variantTags = variant.tags;
39629
+ if (Array.isArray(variantTags)) {
39630
+ checkTags(
39631
+ variantTags,
39632
+ `cards/${file} (side ${sideIdx}, variant ${variantIdx})`,
39633
+ 10
39634
+ );
39635
+ }
39636
+ });
39637
+ }
39638
+ });
39639
+ }
39640
+ } catch (err) {
39641
+ errors.push(`Failed to parse cards/${file}: ${err}`);
39642
+ }
39643
+ }
39644
+ }
39470
39645
  return errors;
39471
39646
  }
39472
39647
  // Build flat bit configs
@@ -39561,6 +39736,11 @@ var ConfigBuilder = class {
39561
39736
  for (const [_tagKey, tag] of tagEntries) {
39562
39737
  tags2.push(...processTagEntries(tag));
39563
39738
  }
39739
+ let cardRef;
39740
+ const cardSetKey = b.cardSet?.configKey;
39741
+ if (cardSetKey && CARDSETS[cardSetKey]) {
39742
+ cardRef = normalizeCardKey(cardSetKey);
39743
+ }
39564
39744
  const bitJson = {
39565
39745
  name: b.bitType,
39566
39746
  description: "",
@@ -39578,7 +39758,8 @@ var ConfigBuilder = class {
39578
39758
  footerAllowed: b.footerAllowed ?? true,
39579
39759
  footerRequired: b.footerRequired ?? false,
39580
39760
  resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
39581
- tags: tags2
39761
+ tags: tags2,
39762
+ ...cardRef ? { card: cardRef } : {}
39582
39763
  };
39583
39764
  const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
39584
39765
  const str = JSON.stringify(bitJson, null, 2);