open-index/open-npm huggingface dataset:
npm package: @palantir/pack.app
Description: PACK main package
Latest version: 0.11.0

# @palantir/pack.app

Main PACK interface package providing the primary entry point for initializing PACK applications.

## Overview

This package provides the main interface for PACK applications, including initialization functions and core type definitions. It contains the application setup logic and re-exports essential types from `@palantir/pack.core`.

## Key Exports

- `initPackApp` - Function to initialize an PACK application instance
- `PackApp` - Type definition for PACK application instances

## Usage

### Basic Usage

```typescript
import { createClient } from "@osdk/client";
import { createPublicOauthClient } from "@osdk/oauth";
import { initPACKApp } from "@palantir/pack.app";

// First, create an OSDK client with your authentication
const auth = createPublicOauthClient(
  "your-client-id",
  "https://your-foundry-instance.com",
  "https://yourapp.com/callback",
);

const client = createClient(
  "https://your-foundry-instance.com",
  "ri.ontology.main.ontology.your-ontology",
  auth,
);

// Then initialize PACK with the client
const app = initPackApp(client, {
  app: {
    appId: "your-app-id",
    appVersion: "1.0.0",
  },
});
```

### Authentication Options

```typescript
import {
  createConfidentialOauthClient,
  createPublicOauthClient,
} from "@osdk/oauth";

// Public OAuth (browser apps)
const publicAuth = createPublicOauthClient(
  "your-client-id",
  "https://your-foundry-instance.com",
  "https://yourapp.com/callback",
);

// Confidential OAuth (server apps)
const confidentialAuth = createConfidentialOauthClient(
  "your-client-id",
  "your-client-secret",
  "https://your-foundry-instance.com",
);

// Static token (CLI/service)
const tokenProvider = () => Promise.resolve("your-token");

// Create client with chosen auth method
const client = createClient(baseUrl, ontologyRid, auth);

// Optional: Override auth in PACK options
const app = initPackApp(client, {
  app: { appId: "your-app" },
  auth: customTokenProvider, // Override client's auth
});
```

## Dependencies

This package depends on `@palantir/pack.core` for its core functionality and provides the main application interface layer.
npm package: @palantir/pack.document-schema.model-types
Description: Minimal types supporting generated PACK schemas
Latest version: 0.7.0

# @palantir/pack.document-schema.model-types

Minimal runtime types and interfaces supporting generated [PACK](https://github.com/palantir/pack) schemas, providing the foundational types for schema-generated models.

## Overview

This package contains the core runtime type definitions that generated schemas depend on. It provides minimal, lightweight interfaces for document schemas, models, and metadata that are used by generated code and runtime validation.

## Key Exports

### Core Types

- `Model<M, Z>` - Interface for schema-generated models with Zod validation
- `ModelData<M>` - Utility type to extract data type from a Model
- `ModelMetadata` - Metadata interface for models (name, documentation, etc.)

### Document Schema Types

- `DocumentSchema` - Interface for complete document schema definitions
- `DocumentSchemaMetadata` - Metadata for document schemas
- `DocumentState` - Runtime state information for documents

## Usage

This package is primarily used by generated code and other PACK packages. It's not typically imported directly by application code.

```typescript
import type {
  Model,
  ModelData,
} from "@palantir/pack.document-schema.model-types";
import { getMetadata } from "@palantir/pack.document-schema.model-types";

// Example of how generated schemas use these types
interface UserModel extends Model<UserData, ZodUserSchema> {
  readonly __type: UserData;
  readonly zodSchema: ZodUserSchema;
  readonly [Metadata]: {
    name: "User";
    // other metadata
  };
}

// Extract the data type from a model
type UserData = ModelData<GeneratedUserModel>;

getMetadata(UserModel).name; // -> "User"
```

## Dependencies

- `zod@v4` - For runtime schema inspection & validation
npm package: @palantir/pack.schema
Description: API package for PACK schema functionality
Latest version: 0.3.1

# @palantir/pack.schema

Programmatic API for defining schemas using TypeScript builders, providing type-safe schema definition with records, unions, and migrations.

## Overview

This package provides builder functions and types for defining document schemas programmatically in TypeScript. It offers an alternative to YAML-based schema definitions, allowing for type-safe schema construction with full IDE support.

## Key Exports

### Schema Definition Functions

- `defineRecord(name, config)` - Define record types with fields and documentation
- `defineUnion(name, variants)` - Define discriminated unions of record types
- `defineMigration(previousSchema, migrationFn)` - Define schema migrations

### Type System

- `Type` - Base type for all PACK field types
- `String`, `Double` - Primitive field types
- `Array<T>`, `Optional<T>` - Composite field types
- `Ref` - References to other defined records/unions

### Utilities

- Field validation and resolution utilities
- Schema conversion and processing functions

## Usage

```typescript
import * as P from "@palantir/pack.schema";

// Define a record type
const Position = P.defineRecord("Position", {
  docs: "A position in 2D space",
  fields: {
    x: P.Double,
    y: P.Double,
  },
});

// Define a record with optional fields and references
const Node = P.defineRecord("Node", {
  docs: "A node in the graph",
  extends: [Position],
  fields: {
    label: P.Optional(P.String),
    connections: P.Array(Ref(() => Node)), // Forward reference
  },
});

// Define a union type
const Shape = P.defineUnion("Shape", {
  circle: Circle,
  rectangle: Rectangle,
  node: Node,
});

// Define a migration
const v2Schema = P.defineMigration(v1Schema, schema => {
  // Migration logic
  return schema;
});
```

## Field Types

### Primitives

- `String` - String values
- `Double` - Numeric values
- `Unknown` - Any value type

### Composites

- `Array<T>` - Arrays of type T
- `Optional<T>` - Optional values of type T
- `Ref<T>` - References to other defined types

## Features

- **Type Safety** - Full TypeScript type checking during schema definition
- **Forward References** - Support for circular/forward references using functions
- **Schema Evolution** - Migration system for schema versioning
- **IDE Support** - IntelliSense and auto-completion for schema building
- **Validation** - Runtime validation of schema definitions
npm package: @palantir/pack.sdkgen.demo-template
Description: Demo template for sdkgen CLI
Latest version: 0.1.0

# @palantir/pack.sdkgen.demo-template

Demo template for the sdkgen CLI showcasing template capabilities with a simple "Hello World" SDK generator.

## Overview

This template serves as a demonstration and testing example for the sdkgen CLI system. It generates a simple "Hello World" SDK package with TypeScript configuration, showing how templates can prompt for user input, process EJS templates, and run generation hooks.

## Features Demonstrated

This template should exercise all features of sdkgen for thorough testing.

- **User Prompts** - Interactive prompts for greeting, author, and license
- **Template Processing** - EJS template files with variable substitution
- **Hook System** - Pre/post generation hooks for custom logic
- **Schema Transformation** - Custom schema transformer for processing input schemas
- **File Handling** - Mix of template and static file processing

## Template Configuration

The template includes:

### Prompts

- `greeting` - Custom greeting message (default: "Hello, World!")
- `author` - Author name (default: "SDK Generator")
- `license` - License type (default: "MIT")

### File Processing

- `**/*.ejs` - Processed as EJS templates with variable substitution
- `_gitignore` - Copied as static file (becomes `.gitignore`)

### Hooks

- `beforeGenerate` - Pre-generation setup and validation
- `afterGenerate` - Post-generation finalization (creates test files, tsconfig.json)

### Schema Transformer

- `default` - Transforms input schemas for template consumption

## Usage

```bash
# Generate a new SDK using this demo template
npx @palantir/pack.sdkgen create my-demo-sdk \
  --template @palantir/pack.sdkgen.demo-template \
  --schema ./my-schema.json

# The template will prompt for:
# - What greeting would you like to use? (Hello, World!)
# - Author name? (SDK Generator)
# - License? (MIT)
```

## Generated Structure

The template creates:

```
my-demo-sdk/
├── src/
│   ├── index.ts          # Main SDK entry point
│   └── helloWorld.ts     # Hello World class with schema integration
├── tests/
│   └── helloWorld.test.ts # Generated test file
├── package.json          # Package configuration with user inputs
├── tsconfig.json         # TypeScript configuration
└── .gitignore           # Git ignore rules
```
npm package: @palantir/pack.state.react
Description: PACK State logic and utilities
Latest version: 0.11.0

# @palantir/pack.state.react

React hooks and components for integrating PACK's real-time state management into React applications.

## Overview

This package provides React-specific bindings for PACK's state management system, offering hooks that seamlessly integrate with React's component lifecycle and provide reactive updates to PACK document state.

## Key Exports

### Hooks

- `useDocRef(app, documentModel, documentId)` - Hook for managing document references
- `useDocMetadata(docRef)` - Hook for accessing document metadata and status
- `useRecord(recordRef)` - Hook for accessing individual records
- `useRecords(collectionRef)` - Hook for accessing and managing record collections

## Usage

```typescript
import { createRecordCollectionRef, createRecordRef } from "@palantir/pack.state.core";
import {
  useDocMetadata,
  useDocRef,
  useRecord,
  useRecords,
} from "@palantir/pack.state.react";
import { DocumentModel, NoteModel } from "@myapp/generated-sdk";
import * as React, {useEffect, useMemo, useCallback} from "react";
import { app } from "./packClient";

type NoteRef = RecordRef<NoteModel>;

export function MyComponent() {
  // Get document reference
  const docRef = useDocRef(app, DocumentModel, "my-document-id");
  const notes = useRecords(docRef, NoteModel);

  const { isMetadataLoading, metadata } = useDocMetadata(docRef);
  // TODO: separate useDocumentStatus to understand data load / live status changes

  const handleAddNote = useCallback(() => {
    docRef.getRecords(NoteModel).add({ text: "New note" });
  });

  if (!isMetadataLoading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h1>{metadata.name}</h1>
      <h2>{`${notes.size} notes`}</h2>
      <button onClick={handleAddNote}>Add note</button>
      {notes.map((noteRef) => (<NoteComponent key={noteRef.id} noteRef={noteRef}/>)}
    </div>
  );
}

const NoteComponent = React.memo<{ noteRef: NoteRef }>(({ noteRef }) => {
  const record = useRecord(noteRef);

  const handleUpdate = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => {
    noteRef.update({ text: e.target.value });
  }, [noteRef]);

  if (record.status === "loading") {
    return <div>Loading...</div>;
  }

  if (record.status === "deleted") {
    return null;
  }

  return (
    <div>
      <textarea onChange={handleUpdate}>
        {record.data.text}
      </textarea>
    </div>
  );
});
```

## Features

- **Reactive Updates** - Hooks automatically re-render components when underlying state changes
- **Type Safety** - Full TypeScript support with proper type inference
- **Loading States** - Built-in handling of document loading and connection states
- **Real-time Sync** - Automatic updates when documents change from other clients
- **React Integration** - Follows React patterns and lifecycle management

## Dependencies

This package requires:

- `@palantir/pack.state.core` for core state management functionality
- React 18+ for hook support