Skip to content

Commit

Permalink
Export and use utility functions from lib/utils
Browse files Browse the repository at this point in the history
Export `createStateSymbol` from `lib/utils`, and export all of utils in `@typespec/compiler` so they can be used by other packages.

Additionally, replace duplicate definitions of `utils` functions in `@typespec/compiler` with imports from `utils`.
  • Loading branch information
steverice committed Jan 26, 2025
1 parent d5aaf39 commit 04faaab
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 1 addition & 12 deletions packages/compiler/src/lib/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import {
} from "../core/types.js";
import { useStateMap, useStateSet } from "../utils/index.js";
import { setKey } from "./key.js";
import { createStateSymbol } from "./utils.js";
import { createStateSymbol, filterModelPropertiesInPlace } from "./utils.js";

export { $encodedName, resolveEncodedName } from "./encoded-names.js";
export { serializeValueAsJson } from "./examples.js";
Expand Down Expand Up @@ -811,17 +811,6 @@ function validateEncodeData(context: DecoratorContext, target: Type, encodeData:

export { getEncode };

export function filterModelPropertiesInPlace(
model: Model,
filter: (prop: ModelProperty) => boolean,
) {
for (const [key, prop] of model.properties) {
if (!filter(prop)) {
model.properties.delete(key);
}
}
}

// -- @withOptionalProperties decorator ---------------------

export const $withOptionalProperties: WithOptionalPropertiesDecorator = (
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Be explicit about what get exported so we don't export utils that are not meant to be public.
// ---------------------------------------
export { DuplicateTracker } from "./duplicate-tracker.js";
export { Queue, TwoLevelMap, createRekeyableMap, deepClone, deepEquals } from "./misc.js";
export { Queue, TwoLevelMap, createRekeyableMap, deepClone, deepEquals, mutate } from "./misc.js";
export { useStateMap, useStateSet } from "./state-accessor.js";

0 comments on commit 04faaab

Please sign in to comment.