@typespec/http 1.0.0-rc.2-dev.5 → 1.0.0-rc.2-dev.7

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 (37) hide show
  1. package/dist/generated-defs/TypeSpec.Http.Private.d.ts +22 -1
  2. package/dist/generated-defs/TypeSpec.Http.Private.d.ts.map +1 -1
  3. package/dist/src/experimental/merge-patch/helpers.d.ts +35 -0
  4. package/dist/src/experimental/merge-patch/helpers.d.ts.map +1 -0
  5. package/dist/src/experimental/merge-patch/helpers.js +43 -0
  6. package/dist/src/experimental/merge-patch/helpers.js.map +1 -0
  7. package/dist/src/experimental/merge-patch/index.d.ts +2 -0
  8. package/dist/src/experimental/merge-patch/index.d.ts.map +1 -0
  9. package/dist/src/experimental/merge-patch/index.js +2 -0
  10. package/dist/src/experimental/merge-patch/index.js.map +1 -0
  11. package/dist/src/experimental/merge-patch/internal.d.ts +3 -0
  12. package/dist/src/experimental/merge-patch/internal.d.ts.map +1 -0
  13. package/dist/src/experimental/merge-patch/internal.js +35 -0
  14. package/dist/src/experimental/merge-patch/internal.js.map +1 -0
  15. package/dist/src/lib.d.ts +64 -4
  16. package/dist/src/lib.d.ts.map +1 -1
  17. package/dist/src/lib.js +29 -0
  18. package/dist/src/lib.js.map +1 -1
  19. package/dist/src/merge-patch.d.ts +5 -0
  20. package/dist/src/merge-patch.d.ts.map +1 -0
  21. package/dist/src/merge-patch.js +312 -0
  22. package/dist/src/merge-patch.js.map +1 -0
  23. package/dist/src/metadata.d.ts.map +1 -1
  24. package/dist/src/metadata.js +2 -2
  25. package/dist/src/metadata.js.map +1 -1
  26. package/dist/src/parameters.d.ts.map +1 -1
  27. package/dist/src/parameters.js +16 -1
  28. package/dist/src/parameters.js.map +1 -1
  29. package/dist/src/payload.d.ts.map +1 -1
  30. package/dist/src/payload.js +19 -1
  31. package/dist/src/payload.js.map +1 -1
  32. package/dist/src/tsp-index.d.ts.map +1 -1
  33. package/dist/src/tsp-index.js +4 -0
  34. package/dist/src/tsp-index.js.map +1 -1
  35. package/lib/main.tsp +90 -0
  36. package/lib/private.decorators.tsp +48 -0
  37. package/package.json +4 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tsp-index.js","sourceRoot":"","sources":["../../src/tsp-index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,OAAO,EACP,IAAI,EACJ,KAAK,EACL,OAAO,EACP,cAAc,EACd,MAAM,EACN,KAAK,EACL,KAAK,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,SAAS,EACT,SAAS,EACT,qCAAqC,EACrC,UAAU,GACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,eAAe,EAAE;QACf,IAAI,EAAE,KAAK;QACX,UAAU,EAAE,WAAW;QACvB,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,KAAK;QACX,aAAa,EAAE,cAAc;QAC7B,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,OAAO;QACf,WAAW,EAAE,YAAY;QACzB,UAAU,EAAE,WAAW;QACvB,OAAO,EAAE,QAAQ;KACe;IAClC,uBAAuB,EAAE;QACvB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,SAAS;QACnB,SAAS,EA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S;QACnB,SAAS,EAAE,UAAU;QACrB,oCAAoC,EAAE,qCAAqC;QAC3E,eAAe,EAAE,gBAAgB;QACjC,eAAe,EAAE,gBAAgB;QACjC,kBAAkB,EAAE,mBAAmB;KACA;CAC1C,CAAC"}
package/lib/main.tsp CHANGED
@@ -271,3 +271,93 @@ model Link {
271
271
  }
272
272
 
273
273
  scalar LinkHeader<T extends Record<url> | Link[]> extends string;
274
+
275
+ /**
276
+ * Create a MergePatch Request body for updating the given resource Model.
277
+ * The MergePatch request created by this template provides a TypeSpec description of a
278
+ * JSON MergePatch request that can successfully update the given resource.
279
+ * The transformation follows the definition of JSON MergePatch requests in
280
+ * rfc 7396: https://www.rfc-editor.org/rfc/rfc7396,
281
+ * applying the merge-patch transform recursively to keyed types in the resource Model.
282
+ *
283
+ * Using this template in a PATCH request body overrides the `implicitOptionality`
284
+ * setting for PATCH operations and sets `application/merge-patch+json` as the request
285
+ * content-type.
286
+ *
287
+ * @template T The type of the resource to create a MergePatch update request body for.
288
+ * @template NameTemplate A StringTemplate used to name any models created by applying
289
+ * the merge-patch transform to the resource. The default name template is `{name}MergePatchUpdate`,
290
+ * for example, the merge patch transform of model `Widget` is named `WidgetMergePatchUpdate`.
291
+ *
292
+ * @example
293
+ * ```tsp
294
+ * // An operation updating a 'Widget' using merge-patch
295
+ * @patch op update(@body request: MergePatchUpdate<Widget>): Widget;
296
+ * ```
297
+ *
298
+ * @example
299
+ * ```tsp
300
+ * // An operation updating a 'Widget' using merge-patch
301
+ * @patch op update(@bodyRoot request: MergePatchUpdate<Widget>): Widget;
302
+ * ```
303
+ *
304
+ * @example
305
+ * ```tsp
306
+ * // An operation updating a 'Widget' using merge-patch
307
+ * @patch op update(...MergePatchUpdate<Widget>): Widget;
308
+ * ```
309
+ */
310
+ @friendlyName(NameTemplate, T)
311
+ @mediaTypeHint("application/merge-patch+json")
312
+ @applyMergePatch(T, NameTemplate, #{ visibilityMode: Private.MergePatchVisibilityMode.Update })
313
+ model MergePatchUpdate<
314
+ T extends Reflection.Model,
315
+ NameTemplate extends valueof string = "{name}MergePatchUpdate"
316
+ > {}
317
+
318
+ /**
319
+ * Create a MergePatch Request body for creating or updating the given resource Model.
320
+ * The MergePatch request created by this template provides a TypeSpec description of a
321
+ * JSON MergePatch request that can successfully create or update the given resource.
322
+ * The transformation follows the definition of JSON MergePatch requests in
323
+ * rfc 7396: https://www.rfc-editor.org/rfc/rfc7396,
324
+ * applying the merge-patch transform recursively to keyed types in the resource Model.
325
+ *
326
+ * Using this template in a PATCH request body overrides the `implicitOptionality`
327
+ * setting for PATCH operations and sets `application/merge-patch+json` as the request
328
+ * content-type.
329
+ *
330
+ * @template T The type of the resource to create a MergePatch update request body for.
331
+ * @template NameTemplate A StringTemplate used to name any models created by applying
332
+ * the merge-patch transform to the resource. The default name template is `{name}MergePatchCreateOrUpdate`,
333
+ * for example, the merge patch transform of model `Widget` is named `WidgetMergePatchCreateOrUpdate`.
334
+ *
335
+ * @example
336
+ * ```tsp
337
+ * // An operation updating a 'Widget' using merge-patch
338
+ * @patch op update(@body request: MergePatchCreateOrUpdate<Widget>): Widget;
339
+ * ```
340
+ *
341
+ * @example
342
+ * ```tsp
343
+ * // An operation updating a 'Widget' using merge-patch
344
+ * @patch op update(@bodyRoot request: MergePatchCreateOrUpdate<Widget>): Widget;
345
+ * ```
346
+ *
347
+ * @example
348
+ * ```tsp
349
+ * // An operation updating a 'Widget' using merge-patch
350
+ * @patch op update(...MergePatchCreateOrUpdate<Widget>): Widget;
351
+ * ```
352
+ */
353
+ @friendlyName(NameTemplate, T)
354
+ @mediaTypeHint("application/merge-patch+json")
355
+ @applyMergePatch(
356
+ T,
357
+ NameTemplate,
358
+ #{ visibilityMode: Private.MergePatchVisibilityMode.CreateOrUpdate }
359
+ )
360
+ model MergePatchCreateOrUpdate<
361
+ T extends Reflection.Model,
362
+ NameTemplate extends valueof string = "{name}MergePatchCreateOrUpdate"
363
+ > {}
@@ -16,3 +16,51 @@ extern dec httpPart(
16
16
  * @param value If true, inapplicable metadata will be included in the payload.
17
17
  */
18
18
  extern dec includeInapplicableMetadataInPayload(target: unknown, value: valueof boolean);
19
+
20
+ /**
21
+ * The visibility mode for the merge patch transform.
22
+ */
23
+ enum MergePatchVisibilityMode {
24
+ /**
25
+ * The Update mode. This is used when a resource can be updated but must already exist.
26
+ */
27
+ Update,
28
+
29
+ /**
30
+ * The Create or Update mode. This is used when a resource can be created OR updated in a single operation.
31
+ */
32
+ CreateOrUpdate,
33
+ }
34
+
35
+ /**
36
+ * Options for the `@applyMergePatch` decorator.
37
+ */
38
+ model ApplyMergePatchOptions {
39
+ /**
40
+ * The visibility mode to use.
41
+ */
42
+ visibilityMode: MergePatchVisibilityMode;
43
+ }
44
+
45
+ /**
46
+ * Performs the canonical merge-patch transformation on the given model and injects its
47
+ * transformed properties into the target.
48
+ */
49
+ extern dec applyMergePatch(
50
+ target: Reflection.Model,
51
+ source: Reflection.Model,
52
+ nameTemplate: valueof string,
53
+ options: valueof ApplyMergePatchOptions
54
+ );
55
+
56
+ /**
57
+ * Marks a model that was generated by applying the MergePatch
58
+ * transform and links to its source model
59
+ */
60
+ extern dec mergePatchModel(target: Reflection.Model, source: Reflection.Model);
61
+
62
+ /**
63
+ * Links a modelProperty mutated as part of a mergePatch transform to
64
+ * its source property;
65
+ */
66
+ extern dec mergePatchProperty(target: Reflection.ModelProperty, source: Reflection.ModelProperty);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http",
3
- "version": "1.0.0-rc.2-dev.5",
3
+ "version": "1.0.0-rc.2-dev.7",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec HTTP protocol binding",
6
6
  "homepage": "https://github.com/microsoft/typespec",
@@ -42,6 +42,9 @@
42
42
  "./experimental/typekit": {
43
43
  "types": "./dist/src/experimental/typekit/index.d.ts",
44
44
  "default": "./dist/src/experimental/typekit/index.js"
45
+ },
46
+ "./experimental/merge-patch": {
47
+ "import": "./dist/src/experimental/merge-patch/index.js"
45
48
  }
46
49
  },
47
50
  "engines": {